Hi Guys
I have a seq file that has three lines eash line has the name and id of student such as
FN1,LN1,ID1
FN2,LN2,ID2
FN3,LN3,ID3
How can I read this file and print it in the screen. I started with the following code, can you help.
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <iomanip.h>
void PrintStruct(const char *, const char *, int);
// Student Structure
struct Student
{
char FirstName[10];
char LastName[10];
int ID;
};
// Main Function
void main()
{
Student aStudent;
ifstream StuData("data.txt",ios:
ut);
if (!StuData)
{
cerr << "File could not be opened\n";
exit(1);
}
cout << setiosflags(ios::left) << setw(20) << "First Name" << setw(20) << "Last Name" << "ID\n";
while (StuData >> aStudent.FirstName >> aStudent.LastName >> aStudent.ID)
PrintStruct(aStudent.FirstName, aStudent.LastName, aStudent.ID);
}
void PrintStruct(const char *fn, const char *ln, int id)
{
cout << fn <<","<<ln<<","<<id;
}
I have a seq file that has three lines eash line has the name and id of student such as
FN1,LN1,ID1
FN2,LN2,ID2
FN3,LN3,ID3
How can I read this file and print it in the screen. I started with the following code, can you help.
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <iomanip.h>
void PrintStruct(const char *, const char *, int);
// Student Structure
struct Student
{
char FirstName[10];
char LastName[10];
int ID;
};
// Main Function
void main()
{
Student aStudent;
ifstream StuData("data.txt",ios:
if (!StuData)
{
cerr << "File could not be opened\n";
exit(1);
}
cout << setiosflags(ios::left) << setw(20) << "First Name" << setw(20) << "Last Name" << "ID\n";
while (StuData >> aStudent.FirstName >> aStudent.LastName >> aStudent.ID)
PrintStruct(aStudent.FirstName, aStudent.LastName, aStudent.ID);
}
void PrintStruct(const char *fn, const char *ln, int id)
{
cout << fn <<","<<ln<<","<<id;
}