Issue with reading till end of line (not file)

Hey, Guys

So I'm trying to read in data till the end of line,I have written a code that KINDA does it, but it never reads in my last word, if anyone could help me out,I would appreciate it a lot.

what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
while ( c != '\n' && in_file)
{


   in_file.get(c);
   phrase = phrase + c;
   if ( c == ' ')
   {
       cout << phrase << ' ';
       phrase.clear();
   }

}


everything is declared okay and it runs, I just never get the last word on the line.

thanks again
Your condition for the cout is that c == ' ', so end the file with a space and you will see the last word.

Though, why clear? You must have something else going on. Other wise you can do getline(in_file, phrase), and this will put the whole line into a file.
Yeah, your right I'm trying to do something, I would love to just use a getline() function but eventually I will have to add a function that will check each word, and its easier for me to do it this way then the other way, BUT know that you bring that up, do you know of a way to

use a getline function then get all of the words out of it?
This might help: http://stackoverflow.com/questions/236129/how-to-split-a-string-in-c

Simpler me to understand:

1
2
3
string strArr[100];
int i = 0;
while (inFile >> strArr[i])  cout << strArr[i++] << endl;
Topic archived. No new replies allowed.