C++ :: Dynamically Deleting Items Out Of Vector

Aug 31, 2014

I have the following code in which I wish to dynamically delete items out of a vector based on the condition of the item in the vector.

The below code works but throws the error: "vector iterator not incrementable" at certain times.

It seems like this happens when the last item in the vector get's deleted. How do I solve this problem?

for (std::vector<PhysicsObject*>::iterator it = CurrentBoxes.begin(); it != CurrentBoxes.end();/*it++*/) {
(*it)->CalculatePhysicsOrientation();
(*it)->DrawMe();
glm::vec3* CurrentBoxPosition = (*it)->GetCurrentPosition();
if (CurrentBoxPosition->y < -750.0f) {
it = CurrentBoxes.erase(it);
}
++it;
}

View 9 Replies


ADVERTISEMENT

C++ :: Deleting Dynamically Allocated Arrays

Oct 13, 2014

I am trying to delete these arrays NumArray1.array and NumArray2.array at the end of my program so that there is not a memory leak. However I always get a double free or corruption error in runtime error with delete[] array_name. I have tried many times to use nullptr, but no matter what my compiler does not recognize it as being declared in the scope of my delete function. (I have commented out the that function for now.)

What is also strange about this is that I can perfectly use delete[] a1.array, which corresponds to NumArray1.array, but any of the other times I have tried to use the command, it has always resulted in syntax or runtime errors. Online resources do not adequately explain this scenario, though I am sure it exists elsewhere. all of my attempted solutions have failed, and I am completely at a loss. how to free the dynamically allocated arrays at the end of my program?

#include <iostream>
#include <assert.h>
using namespace std;
// Define a struct type, each struct type variable has three
// member variables: array, capacity, and length. Togther these
// three variable represent a partially filled array.

[code].....

View 1 Replies View Related

C++ :: Creating / Filling And Deleting Dynamically Allocated Array Of Objects

Jul 26, 2012

Project compile successfully but console turn off with "Windows " with error doesn't print or get anything

Code:
#ifndef Point_HPP // anti multiply including gates
#define Point_HPP
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>

[Code] .....

View 2 Replies View Related

C++ :: Get Items From Map And Add To A Vector

Mar 10, 2014

I rote this code in my program

JSONNode::const_iterator iter = root.begin();
for (; iter!=root.end(); ++iter) {
const JSONNode& arrayNode = *iter;
std::string type = arrayNode["type"].as_string();
if(type == "node")

[code]......

But when i try to ptint id of second item std::cout<<"Item Id ->>>>>>>>>>>>>" << collection[2].GetId() << std::endl; it gets a blank value. but size of the collection is 82, get the correct value for the collection size.

View 1 Replies View Related

C/C++ :: Get Items From Map And Add To Vector

Mar 9, 2014

I wrote this code in my program

JSONNode::const_iterator iter = root.begin();
for (; iter!=root.end(); ++iter) {
const JSONNode& arrayNode = *iter;
std::string type = arrayNode["type"].as_string();
if(type == "node")

[Code] .....

But when I try to ptint id of second item std::cout<<"Item Id ->>>>>>>>>>>>>" << collection[2].GetId() << std::endl;
it gets a blank value. but size of the collection is 82, get the correct value for the collection size.

View 1 Replies View Related

C/C++ :: Getting A Vector To Print Out 12 Items Per Line

Sep 2, 2013

I'm having problems fully comprehending how to do this task (I'm only going to include my function code since that's the basis of my problem). How should I go about getting my vector to print off 12 items per line. Here's my current function.

void printVec(const vector<int>& v) {
    for(unsigned i=0; i < 12;i++)
        cout<<v[i]<<" "<<endl;
}

View 2 Replies View Related

C++ :: Adding Items From File To Vector Of Class

Oct 10, 2013

how to add a list of information from a file to a vector of a class. Here is my code:

Champion_Info.h
#ifndef CHAMPION_INFO_H_INCLUDED
#define CHAMPION_INFO_H_INCLUDED
#include <vector>
#include <string>

[Code].....

View 6 Replies View Related

C++ :: SDL Deleting From Vector

Apr 13, 2013

Simple rect collision detection

bool check_collision(SDL_Rect *box1, SDL_Rect *box2){
if(box1->x+box1->w<=box2->x)return false;
if(box1->x>=box2->x+box2->w)return false;
if(box1->y+box1->h<=box2->y)return false;
if(box1->y>=box2->y+box2->h)return false;

return true;

[Code] ...

The order of the game is of course standard.

1.handle input
2. handle logic
3. render
4. update

It's all pretty simple and straight forward, but oftentimes (not always) when the weapon hits the asteroid, the program crashes. If for example I turn off the delete main_weapon[i] and main_weapon.erase(main_weapon.begin()+i); the program works perfectly, but of course the bullets go right though the asteroid object, which is not what I want. It's only the weapon deletion which is causing no end of trouble.

View 7 Replies View Related

C++ ::  Deleting Vector Of Pointers?

Nov 23, 2013

Currently I am implementing the A* algorithm in C++. I have chosen to use a hybrid of a '2D vector grid' and two 1D pointer vectors to specific places in the '2D vector grid'. I have chosen to do it this way, so I can access the nodes using coordinates and also for iterating over the appropriate nodes(rather than the whole '2D vector grid').

In the below examples I have not included the full code because I deemed it irrelevant to the question.

vector <int> CInGame::AStarAlgorithm(vector<vector<bool>>& resistanceMap, int startX, int startY, int targetX, int targetY, int cutOff) {
vector <int> returnVec;
vector <vector<CNode>> twoDimNodes;
vector <CNode*> openSet;
vector <CNode*> closedSet;

[code].....

The error is:

_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

do I need to free the pointers or is it done automatically? If not then how would I do this?

View 3 Replies View Related

C++ :: Deleting Vector Of Pointers?

Oct 14, 2014

I made a vector of pointers and the problem is that I have trouble deleting the pointers in the vector. I used to simply do vector.clear() or vector.erase() however it does not clear the actual memory. And I tried something like this:

std::vector<Foo*> Vector;
std::vector<Foo*>::iterator i;
for (i = Vector.begin(); i < Vector.end(); i++)
delete *i;

View 5 Replies View Related

C++ :: Repeat Found - Deleting In A Vector

Oct 12, 2013

I created a very basic program which contains a vector (my vector) that holds 0, 1 and 1. This program compares each element in the vector. If the element after the one currently being compared is equal to it, it outputs "repeat found!" Now this all works perfectly, but my next step was to erase the repeated one. Everything was working up until the delete step. I get a weird error that says "vector iterator not dereferencable" .

// vector::begin/end
#include <iostream>
#include <vector>
using namespace std;
int main () {
vector<int> myvector;

[Code] ....

View 6 Replies View Related

C++ :: Deleting A String Object In Vector?

Sep 21, 2013

Here's my code so far:

case DELETE_TITLE:
std::cout << "Game to remove from list: ";
std::cin.ignore();
getline(std::cin, gameTitle);
for (iter = gameList.begin(); iter != gameList.end(); ++iter) {

[code]....

It deletes the text from the string but not the index it self.

It deletes the text but when I print the list of game titles it has it there blank. I want it to completely remove the object from the vector from where it was deleted

View 1 Replies View Related

C++ :: Deleting Vector With Char - Segment Fault

Apr 19, 2012

The below code is giving me segment fault during delete [] (*iter) sometimes. Is it not the proper way to delete the vector with char *

Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<char*> nameList;
for (int i=0;i<1000;++i)

[Code] ....

View 7 Replies View Related

C :: Allocate Dynamically A Vector If Input Of User Exceeds 5 Times

Jan 31, 2013

i don't understand why this program crash if i'll insert a number more of 5 times... i want to allocate dynamically a vector if the input of the user exceeds 5 times... this is the code:

Code:

#include <stdio.h>
#include <stdlib.h>
int main()
{
int * vettore, n;
unsigned int len=1;
}

[code]....

View 2 Replies View Related

C# :: How To Stack List Items

Nov 18, 2014

I do some research about getting the coordinates from the list items but without success. I would like to make that when i press down my mouse button that little blocks fall "out" my mouse and stack on top of eachother.

that first works. When i press the mouse button i draw squares and the fall to the bottom of the screen, but the stack part not.

here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;

[Code]....

View 14 Replies View Related

C# :: Removing Items From ListBox

Mar 5, 2014

I'm working on creating a windows form with a listbox, textbox, and 2 buttons (add,remove). I need a way of removing every string matching the contents of the textbox from the listbox. Here's what I have:

for (int i=0;i<listBox1.Items.Count;i++)
{
//...
listBox1.RemoveAt(i--)
}

Seems to work, but I need a way to show a error message once the user clicks 'remove' and no items in the listbox match.

View 6 Replies View Related

C# :: Display Items From Dictionary

Jan 18, 2014

I am creating a student management system (using classes) for my assignment and am stuck with designing UI. I made the classes but am not sure what the best control is to display items from a Dictionary<> object. Right now I am using the ListView because of the columns in details view...just want to know if there is a better, simpler control I could use if i want to display data (without using sql)...or is the good old "next" and "previous" option the simplest?

View 9 Replies View Related

C :: Splitting TXT File Items Into 2 Different Arrays

Oct 21, 2014

im new to programming and new to C, just started with arrays and im somewhat stucked, where i have a .txt file which contains items and prices. I want the items and the prices split into 2 different arrays

The .txt looks like that:

orange 0.89
banana 0.79
apple 0.59

I now want to split the items in a char items[100][100] and float prices[100]. how to split this, preferably with fscanf ?

View 7 Replies View Related

C++ :: Sorting Dynamic Stack Items?

Sep 26, 2013

Create a program that contains the following functions:

-create two dynamic stacks with integer data contained in an external file.
-Sort items in stacks by the selection sort method
-Record outputs in an external file.

Main function main ()-menu selection functions and check the status of the data

I shouldn`t use arrays or STL only can use vectors but i dont know how to do it howw to make dynamic stack with vectors and how to sort it with selection sort?

View 1 Replies View Related

C++ ::  Switch Statement - Summing Items

Nov 6, 2014

I'm creating a program that is combining functions to show a menu to a user then the user picks numbered items which results in the totalling of a bill for them.

Where I'm stuck is after they're entered their selections, how to take them and sum them up. I've been trying with a switch statement, but I'm not sure if this is the right method. Is it even possible to sum separate cases of a switch statement together? Below is the code I've gotten so far:

#include <iostream>
#include <iomanip>
using namespace std;
void showMenu ();
void showBill (double, double, float, double);
void changeDue (double, int);

[Code] ....

View 3 Replies View Related

C++ :: Using A Textbox And Other Items Between Multiple Forms

Oct 31, 2013

I am writing a program in Visual C++ 10 with 2 forms.

In the first form I have a textbox and a button. The button opens the second form.

In the second form, I have a button that changes the text in the textbox in form1 to an item from a listbox in form2.

Here is my problem. When I do the code for the button in form2 to change the textbox in form1 I get the errors:

error C2065: 'textBox1' : undeclared identifier
error C2227: left of '->Text' must point to class/struct/union/generic type

I thought maybe I should just include the "Form1.h" file but I can't do that because I already included "Form2.h" in form1 in order to be able to open the second form. If I try to include form1 in form2, it says that the code to open form2 is an error now.

My question is, how can I access identifiers such as "textbox1" from other forms and other files when I already used the first form to open the second form? I also want to know how to do this for all identifiers between all files.

how to print the selecteditem from a listbox into a textbox because that doesn't work by just setting them equal either.

Here is my code:

#pragma once
#include "Form2.h"
namespace Test1 {
using namespace System;

[Code].....

View 11 Replies View Related

C# :: Set A Checkbox On Dropdown Menu Items?

Sep 14, 2014

I'm using winforms and I want to set a checkbox on a dropdown menu item, but I don't know how to access the dropdown menu items.

I know ToolStripMenuItem items are attached to ContextMenuStrip items but I'm not sure how to navigate into the ToolStripMenuItem section to read/set those menu items.

ToolStripMenuItem listbox_font_size;
cmsListBox = new ContextMenuStrip();
cmsListBox.Items.Clear();

[Code].....

View 14 Replies View Related

C# :: How To Size ListBox Height To Items

Jul 24, 2014

Is there a way to set the height of a listBox to show all of the items without having to kick in the vert scrollbars? I've searched on this question but can't find how to do this.

I want to kind of auto-size my listBox height to accommodate my items (within reason and perhaps set a max height which would kick in the vert scroll bars.

View 9 Replies View Related

C Sharp :: How To Output Items In A Listbox

Mar 31, 2013

What codes in c# will output items in a list box?

View 2 Replies View Related

C Sharp :: Move Items In ComboBox?

May 17, 2012

I have a data-bound ComboBox and I populate a DataSet with the values returned from a SQL query.
 
        public DataSet CompanyArray(DataSet dataSet) {
            SqlConnection connection = InstancesTest.IDataInterface.DefineConnection();  
            SqlCommand command = new SqlCommand();
            command.CommandText = "usp_CompanyArray";
            command.CommandTimeout = 20000;

[code]....

All this works fine. The reason I populated it in an array was so that I could sort the items alphabetically. I know I could just do an "order by" in SQL but I chose this route.

What I'm after is putting a "Please Select" at index 0 in the ComboBox. How can I move this value to the top of the list, without reordering the sorted list?And I don't really want to insert a "Please Select" as a first row in a database table.

View 2 Replies View Related

Visual C++ :: How Many Items Exist In A Dialog Box

Sep 11, 2013

I was wondering how can we know how many items exist in a dialogbox? If there any way that i can get the items ID in a dialogbox by having just the dialogbox's object or handler? Or any way that we can get a dialogbox content by coding.

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved