I'm having trouble inserting char* into a vector< char*>
When I do the following:
string str = "Hello b World d"
char *cstr, *p;
vector<char*> redn;
cstr = new char [ (str.size)+1 ];
strcpy(cstr, str.c_str());
//here I tokenize "Hello b World d"
p = strtok(cstr," ");
while(p!=NULL){
redn.push_back(p);
cout << "just pushed back: " << redn.back() << endl;
p = strtok(NULL," ");
}
delete[] cstr;
//now check
for(it= redn.begin(); it < redn.end(); it++)
cout << *it << endl;
I got an output of:
just pushed back: Hello
just pushed back: b
just pushed back: World
just pushed back: d
p0s
World
d
It seems to me that *it is pointing to the wrong thing.. Would anybody tell me what's going on and how I could fix this?