Hello,
I need to get the following string
"12332321213,So meText,3.141592 654"
into constituent variables: an unsigned long int, a string and a double. So far I have,
Now I have a vector of strings. So the question arises: how do I convert the string "1233232121 3" to a long int and "3.14159265 4" to a double? Of course, atoi() comes to mind but it looks like it only converts to single precision integers.
I tried static_cast<uns igned long int>() but I get the compile-time error " invalid static_cast from type `std::string' to type `long unsigned int' ".
(An irrelevant aside: how do I specify what kind of code I'm posting in this forum because mine comes up as 'text' and not 'cpp'?)
I need to get the following string
"12332321213,So meText,3.141592 654"
into constituent variables: an unsigned long int, a string and a double. So far I have,
Code:
string line = "12332321213,SomeText,3.141592654"; unsigned long int id; // should become 12332321213 string name; // should become "SomeText" double number; // should become 3.141592654 vector <string> lineTokens; istringstream iss(line) // Create string stream string token; while (getline(iss,token,',')) { lineTokens.push_back(token); }
I tried static_cast<uns igned long int>() but I get the compile-time error " invalid static_cast from type `std::string' to type `long unsigned int' ".
(An irrelevant aside: how do I specify what kind of code I'm posting in this forum because mine comes up as 'text' and not 'cpp'?)
Comment