-
Well if you're only writing this for that file, you could read in until a space and read in until a newline each time through the loop, after a few iterations, you'll end up with BallSpin in the string.
Code:
do {
getline(fin,test, ' ');
getline(fin,test, '\n');
cout<<test<<endl;
} while (test != name);
-
That is true but I am trying to start the read at ballspin not to get ballspin.
I am may have been unclear to begin with because I am unclear on what is need to solve the problem and what the problem really is in the end. I thought it would be easy to find ballspin start reading the stop at ;. but I can see now it is not so easy.
I am very appreciative for your help. I know with your help I will be able to solve this problem.
-
There is no basic way to find something in a stream without having been reading from it already. But regardless, once you find the word ballspin, exit the loop, then start another loop that just keeps concatinating everything onto that same string until you get to the semicolon. That's about the easiest way to do it.
-
whould I do something like what is shown below?
Code:
do{
getline(fin,test, ' ');
getline(fin,test, '\n');
cout<<test<<endl;
}while (test !=name);
test += blah;
do{
getline(fin,blah, ' ');
getline(fin,blah, '\n');
}while (blah !=";");
-
More like this:
Code:
do{
getline(fin, test, ' ');
getline(fin, test, '\n');
}while (test !=name);
do{
getline(fin, blah, '\n');
test += '\n' + blah; // Don't forget getline() doesn't read in the delimeter
}while (blah !=";");
cout << test << endl;
-
only one issue if I cahnge it to BallExplode then it does not do any thing? is there something I have to put in so it will read it sence it is at the top?
Edit:
never mind I just have to be carefull with the spaces.
Right now I am going to extract the data and if it works then I am all dont all thanks to you and your greate wisdom.
Edit2:
So how do I take string test and take out the individuel strings from it?
-
can any one else give me some ideas?
-
I didn't follow the entire thread, so this may not be what you are looking for, but to take the individual strings out of an existing string, use a stringstream from <sstream>. It works just like an iostream or a file stream, so you can use getline or operator>> on it.