hello
I am having problems with reading input lines.
i wanna tell my progrem that whan i input a line it have to read diferent strings.
if i input a line:
n10000 x-123 465 y
i have to get this
string strn ( line , 'n' , 'x');
string strx (line , 'x' , 'y');
cout << " n = " << strn <<endl;
cout << " x = " << strx << endl;
so when i run a program i shuld get this output:
n = 10000
x = -123465
it wont work couse the start of astring is wrong why
here is myCode:#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string str; cout << "Enter a number: "; getline(cin, str); stringstream ss; string s4 ( str , 'n' , 'x'); //if i write a number instead of 'n' it will work and start reading string s5 (str , 'x' , 'y'); ss << s4 ; cout << " s4 = " << s4 << endl; cout << " s5 = " << s5 <<endl ; //int i; //ss >> i; //int i; // if ( ss >> i ) // cout << "Valid conversion to int:\n " << i <<"\n"; // cout << " i + 100 = " << ( i + 100)<<endl; /*else cout << "Invalid input"; } */ }



LinkBack URL
About LinkBacks


