-
convert string to int
I have this program where the user can enter commands, followed by either a string, or int, depends on which command asks for.
so i store the input all into one string, then cut it into two strings command and input
is there a simple way to convert a string of numbers into integers?
-
Code:
#include <sstream>
#include <string>
#include <iostream>
int main()
{
std::string str = "123 456 789";
std::stringstream sstr(str);
int number;
while( sstr >> number )
std::cout << number << std::endl;
return 0;
}
Output:
-
thanks, worked perfectly :)