can you some help me my file is not compile i got this example from the proffesor in class i dont really understand what it does can someone explain it to me. all i know it is supposed to open a file and write into it.
Code:#include<stdio.h> #include<conio.h> #include<iostream> #include<fstream> using namespace std; class player { char name[21]; int score; public: friend istream &operator >>(istream cin, player &p) { cout<<"player name =>"; cin.getline(p.name,21); cout<<"score="; cin>>p.score; return cin; }; friend ostream & operator<<(ostream &cout, player &p) { cout<<p.name<<"score="<<p.score<<endl; return cout; }; }; main() { int count =0; player p; ofstream file1("c:score.doc",ios::out); if(file1==0) { cout<<"file opening eor"; getch(); exit(1); } cout<<"enter player data or ctrl-z to stop"; cin>>p; file1.write((char*)p,sizeof(player)); getch(); }



LinkBack URL
About LinkBacks


