You are here:

C++/Nested Structures


Hi, I am not sure if I am doing anything wrong. But I can't get out the value from my arrays. Here is what I have done so far.....
The code I have placed is something like to get the values out is...

cout << "Name: " << << endl;

but it doesnt seem to work?

#include <iostream>
#include <fstream>
using namespace std;

struct Player
char name[40];
char league[5];

struct Team
Player play;
char position[5];
char owner[5];

Team NFL;

void read_file();

void main()
cout << "Name: " << << endl;

void read_file()
ifstream file_in; ("A:\\fantasy.dat");

file_in.getline(, 40, ' ' );
file_in.getline(, 5, ' ' );
file_in.getline(NFL.position, 5, ' ' );
file_in.getline(NFL.owner, 5, '\n' );



Shirley Valencia , Thank you for your question.

The problem may be in statements like

file_in.getline(, 5, ' ' );

This statement will read in text from the input file, stopping at the first space character. If your data contains space characters, such statements will read data incorrectly. You probably want to use

file_in.getline(, 5);

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 All rights reserved.