c++ - convert array sting into char -
c++ - convert array sting into char -
i have taken txt file , place line line array of string. trying split string can save word word in separate array. kindly tell me how shell convert array of string char.
for illustration
string line[15]; // line[0] has : there before // line[1] has : after char * pch; char *c = line.c_str(); // string char (i getting error here. body know?) pch = strtok (c," "); while (pch != null) { printf ("%s\n",pch); pch = strtok (null, " "); }
error: c2228: left of '.c_str' must have class/struct/union
string line[15];
array of strings. when have line.c_str();
line pointer string , not string itself. pointer doesn't have .c_str()
method , that's why compiler complaining. (pointers don't have methods , hence compiler tells left hand side of look must class/struct/union type). prepare want index array string. can like: line[0].c_str();
additionally can't write returned c_str()
returns const pointer. you'll need re-create results c_str
first before operate on if going alter in place.
also might worth mentioning there's c++ ways of doing tokenizing, might find examples here split string in c++? . lastly time did using boost made utilize of boost::tokenizer library.
c++ arrays
Comments
Post a Comment