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.
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.
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.
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.
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.
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?
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;
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;
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
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; }
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;
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.
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?
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 ?
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?
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:
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;
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();
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.
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.
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.