1

I am writing a program that can read in statistics from a basketball team. The file lookes like this:
Joe 3 114 9-19 1-3 2-4 3 15 4 2 1 2 3 21
I have created an array of structs to read all of them in
I used ifsteam infile2("file.txt") to open file
To test it I made my code:

infile2 >> Player[0].Name;
cout << Player[0].Name << endl;

I get nothing!! I haven't the slightest clue what is wrong! If anyone can help PLEASE do so!!

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by jonsca
0

Hi tasky23,

You need a bit more to open the file. Declaring an instance of ifstream is the correct start but it should read:

ifstream infile2;
//then to open the file.
infile2.open("file.txt",ios::in);

then you may do your infile2 >> Player[0].Name;

Hope that gets you on the right path.

0

Hi tasky23,

You need a bit more to open the file. Declaring an instance of ifstream is the correct start but it should read:

ifstream infile2;
//then to open the file.
infile2.open("file.txt",ios::in);

See: http://www.cplusplus.com/reference/iostream/ifstream/ifstream/ his notation is a shortcut.

@OP: I think the brevity of your post is excellent (though the title could use some dressing up ;) ) but in this case people might need a bit more code to get at the heart of the problem more quickly.

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.