Let's say you have a string called in and you need the ints var1 and var2.
Then:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <string>
#include <sstream> // Needed to use stringstream.
...
...
string in, v1, v2;
getline(cin,in);
int end=-1, var1, var2;
if(in.find_first_not_of("1234567890, ")==std::string::npos){ // First check on input.
end=in.find(' ');
if(!(in.find_first_of ("1234567890, ",end+1)==std::string::npos)){ // Second check on input.
v1=in.substr(0,endComm);
v2=in.substr(endComm+1,in.length()); // This makes sub-strings.
stringstream(v1)>>var1;
stringstream(v2)>>var2;} // This does the actual work.
}
PS: You may need to replace the , (comma) in "1234567890, " with a . (dot) depending on your keyboard layout.
Although that's only needed if you change the code to work with floats.