It really should be a simple conversion but there's no way I can think of to get this to work
I got a string with a number in it like " the number is 22"
And i want to take this 22 and store it in an integer,
the only thing i could do was use a character conversion for each one , and not only do i get some kind of ascii code for the numbers , but its pointless cause it can't be used for more than one character.
#include <iostream>
#include <sstream>
usingnamespace std;
int main () {
stringstream ss (stringstream::in | stringstream::out);
ss << "the number is 22";
// eat the alpha and spaces...
char ch = 0;
while (ss.get(ch) && !isdigit(ch));
//put back the numeric;
ss.putback(ch);
// finally read the number into a variable
int val =0;
ss >> val;
cout << val << endl;
return 0;
}