Nov 19, 2012 at 1:21pm UTC
Hi for some reason this crashes for me
1 2 3 4 5 6
struct Struct
{
char * NAME;
int OBJ;
};
std::vector<Struct> Logged;
1 2 3 4
for (int i = 0; i < 50; i++){
Logged[i].NAME = "test" ;
Logged[i].OBJ = 12345;
}
whats am i doing wrong with that?
here is a image of what happens when i debug it
http://i.imgur.com/U5qrH.png
Last edited on Nov 19, 2012 at 1:26pm UTC
Nov 19, 2012 at 1:35pm UTC
what if i dont know how big i want the vector to be?
i dont think i can use the push_back for this as the way i need to read it
Nov 19, 2012 at 1:43pm UTC
what if i dont know how big i want the vector to be?
Then use push_back.
i dont think i can use the push_back for this as the way i need to read it
You can use push_back for this.
Last edited on Nov 19, 2012 at 1:43pm UTC
Nov 19, 2012 at 1:52pm UTC
thanks guys
but push_back still dont really work for me unless you know how to do it better
because i need to be able to know where abouts each objects are in the vector. an then i need to be able to reset that vector again an not put it on the end of the vector
Nov 19, 2012 at 1:54pm UTC
push_back is for adding objects to the end.
Your other problem is completely different. Sounds like you need to think a bit and come up with something like this:
Get new object.
Look through vector to see if this is a new one or not.
If new, push_back onto the end.
If not new, replace existing one.
Last edited on Nov 19, 2012 at 1:54pm UTC
Nov 19, 2012 at 1:56pm UTC
a named object sounds like something a map could deal with