c++ - ofstream is writing date and time only -


i trying write text file after code executes can see time , date written in file rather actual data need written file.

what strange when run program can see data stored in memory until close windows console not storing data file.

i have code uses ifstream , has close @ end not sure if might keeping file open. when writing file program writes @ last position of cursor rather end of file. here code write file.

void createperson (person persons[], int* count) {     char fullname[100];     char personaddress[200];     int marks1;     int marks2;     int marks3;     int marks4;     int marks5;     int personnumber;     string persongender;      ofstream outfile("testfile.txt", std::ios_base::app);  if(outfile.fail()){   cerr << "file cannot opened" << endl;   }      cout<<"enter person's number: "<<endl;     cin>>personnumber;     cout <<"enter person's full name: "<<endl;     cin.ignore();     cin.getline(fullname,50);     cout<<"enter score marks1: "<<endl;     cin>>marks1;     cout<<"enter score marks2: "<<endl;     cin>>marks2;     cout<<"enter score marks3: "<<endl;     cin>>marks3;     cout<<"enter score marks4: "<<endl;     cin>>marks4;     cout<<"enter score marks5: "<<endl;     cin>>marks5;         cout<<"enter person's address: "<<endl;     cin.ignore();     cin.getline(personaddress,50);     cout<<"enter person's sex: "<<endl;     cin>>persongender;      persons[*count] = person(personnumber,fullname,          marks1,marks2, marks3, marks4, marks5,          personaddress, persongender);     (*count)++;      outfile << persons[*count].getpersonnumber()<<":";  outfile << persons[*count].getpersonname()<<":";   outfile << persons[*count].getmarks1()<<":";  outfile << persons[*count].getmarks2()<<":";  outfile << persons[*count].getmarks3()<<":";  outfile << persons[*count].getmarks4()<<":";  outfile << persons[*count].getmarks5()<<":\n";  outfile << persons[*count].getpersonaddress()<<":";  outfile << persons[*count].getpersongender();   outfile.close();      cout << persons[*count].getpersonname(); } 


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -