filess

let say i have a file
0 sandy a
1 billy b
2 tom c
3 tiffany d
4 tommy e
struct student for the example
{
string person
int studnetId
char grade
}
student class[5]
im working on a project this isnt the text file i just need someone to explain getline to me and im also using a struct that an array how would i grab only the names if i wanted to because im confused on that part

while(inFile >> student[5].person)
cout << student[5].person << endl;
There are two versions of getline(...). Read this for more details:

http://www.cplusplus.com/reference/string/string/getline/
http://www.cplusplus.com/reference/istream/istream/getline/

Basically they do the same:

Read all characters until the delimiter or end of file is reached. Notice that the delimiter is removed from the stream (while the operator>> does not).

how would i grab only the names
You could temporary variables for this:
1
2
while(inFile >> tmp1 >> student[5].person >> tmp2)
cout << student[5].person << endl;
1
2
3
4
5
int tmp1//should they be int
int tmp2

while(Infile >> tmp1 >>student[5].person >> tmp2)
cout << student[5].person << endl;
Topic archived. No new replies allowed.