Reading words seperated by spaces

I am trying to read words separated by spaces from a file and store it in a c-string. The file i am reading from is set up like this:

1432532
Last, First
1234325213
last, first

I can read the numbers fine, but when I try to read the words, all i get is the "last," Here is how I am trying to read it.

1
2
3
4
5
6
7

typedef char Name[40];
Name employee[24];

inFile >> employee[0];
cout << employee[0] << endl;


So how do I get past that white space? Thanks a lot.
It's because the bitshift IO operators will skip the whitespace that it reads in from. Use something like getline.
ok so i'm a little confused here...

1
2
3
4
5
6
7

typedef char Name[40];
Name employee[24];

inFile.getline (employee[0], 30);
cout << employee[0] << endl


The 30 is just how many characters the string is going to store, correct?
And, why does this output nothing lol
Look up getline, I don't know for sure why. Getline is low-level manipulation of characters in the stream and its behavior is less predictable than formatted >>.
http://www.cplusplus.com/reference/iostream/istream/getline/
And I'd advise you to use std::string rather than char[].
I still cannot figure this out.. any help would be appreciated.
Topic archived. No new replies allowed.