Any help would be appreciated with this program :

I have a file with 5 lines....each line has name, id , phone ...etc...
I have to read that intro an array of structures and display the results.
This is what I have so far .. I doesn't not display anything

#include <iostream>
#include <fstream>
#include <string>
#include<iomanip>

using namespace std;

struct StudentInfo
{
    string name;
	int account_id, phone;
	float checking, saving;
};

int main ()
{
	ofstream file1; 
    const int MaxSize = 5;
    StudentInfo myarray[MaxSize]; 

	file1.open ("users.txt");
	
for (int i=0; i<MaxSize; ++i)
{	

      file1<<myarray[i].name; 
	  file1<<myarray[i].account_id;
	  file1<<myarray[i].saving;
	  file1<<myarray[i].checking;
	  file1<<myarray[i].phone<<endl<<endl;
           
}

   
		
//    }
    return 0;
}

Recommended Answers

All 4 Replies

I would guess that it's because you have no data to display. Where is myarray loaded?

you've done everything for writing to a file, but there is absolutely no code for opening and reading from a file.

The file exists already . I just thaught I might be able to assignt with studentifo myarray[maxsize]. in the loop I think that every line in the file will be stored in the array. I don't have to input anything in the file . Just read and output 5 students into array and display . I'm really not c++ savvy . All I need is a good direction

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.