Hello everyone,
I have a project to do which involves reading each line of text from an input file
which holds integers.
Each line represents a polynomial, and I have to rearrange it in canonical form which is sorted by powers.
I was wondering if there is a string tokenizer function for c++ such as the one from Java.
an example line would be
-1 0 5 1 20 3 -9 2 -2 1 1 2 -2 3
which would be
-x + 5x^1 + 20x^3 - 9x^2 - 2x + x^2 - 2x^3
Each integer is separated by a space.
string line;
ifstream myfile("input.txt");
if(myfile.is_open()){
while(!myfile.eof()){
getline(myfile, line);
cout << line << endl;
}//while
myfile.close();
}//if
else cout << "Unable to open file" << endl;
Is there a way to extract 2 digits at a time from the string "line"?
Thanks.