#include<iostream> #include<fstream> #include<string> using namespace std; class clasa {public: int n; char t; string st; }; void citeste(void) { clasa a; fstream file("file.tx", ios::in); if( file.is_open()) cout<<"\n la deschis \n"; file.seekg(0); file.read( (char*)&a, sizeof(clasa) ); cout<<a.n<<a.t<<a.st; file.close(); } void scrie(void) { clasa a; fstream file("file.tx", ios::out | ios::trunc); if( file.is_open()) cout<<"\n la deschis \n"; cin>>a.n>>a.t>>a.st; file.seekp(0); file.write( (char*)&a, sizeof(clasa)); file.close(); } int main(void) { //cout<<sizeof(clasa); scrie(); citeste(); system("PAUSE"); return 0; } |
system("PAUSE")
as UNIX doesn't have a pause). The only thing I can suggest is putting an endl on your cout (and some spaces)cout<<a.n<<" "<< a.t<<" "<< a.st << endl;
|
|
|
|
system( "read -p \"Press any key to continue...\"" );