hi all I need advice here I'm having a bit of a dilemma with this algorithm. We just started reading info from a text file check it out.
Code:
#include < iostream.h >
#include < fstream.h >
struct person
{
int id;
float gpa;
char name[19];
};
class myclass
{
private:fstream f;
person p;
public: void display1( )
{
char line[80]; fstream f;
f.open("data.txt" , ios::in);
while( true )
{
f.getline(line, 19, '\n');
f>>p.id>>p.gpa;
if(!f.fail())
break;
}
f.close();
}
void display2( )
{
f.open("data.txt", ios::in);
f>>p.id>>p.gpa;
while(!f.eof())
{
cout<<p.id<<"\t"<<p.gpa<<endl;
f>>p.id>>p.gpa;
}
f.close();
}
void display(char *fname)
{
f.open(fname, ios::in);
while(true)
{
f>>p.id>>p.gpa;
if(f.fail()) break;
cout<<p.id<<"\t"<<p.gpa<<endl;
}
f.close();
}
};
void main()
{
myclass cs131;
cout<<"This is the content of the file\n";
cs131.display1();
cout<<"This is the content of the file\n";
cs131.display2();
cout<<"This is the content of the file\n";
cs131.display("data.txt");
}
Anyways I can't seem to get the name to print out no matter what I do anyone have any ideas