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!!

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.

Have you allocated memory for Player ?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.