Shouldn't this program create a file called repo.txt? It is working, but I don't see the file repo in my folder. WHY? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Shouldn't this program create a file called repo.txt? It is working, but I don't see the file repo in my folder. WHY?

#include<iostream> #include<iomanip> #include<cstdlib> #include<fstream> using namespace std; class players { char name[20]; int goals; int assists; float score; public: players(){goals=0; assists=0; score=0;} void writeData(); void readData(); }; void players::writeData() { cout<<"Enter Name: "; cin>>name; cout<<"Goals: "; cin>>goals; cout<<"assists: "; cin>>assists; score=(goals+assists)*20; } void players::readData() { cout<<name<<setw(10)<<goals<<setw(10)<<assists<<setw(10)<<score<<endl; } int main() { players p[2]; fstream file; file.open("repo.txt", ios::in|ios::out); //this line of code for(int i=0; i<2; i++) { p[i].writeData(); file.write((char *)&p[i], sizeof(p[i])); } cout<<"OUTPUT"<<endl; file.seekg(0); for(int i=0; i<2; i++) { file.read((char*)&p[i], sizeof(p[i])); p[i].readData(); } file.close(); return 0; }

19th Jun 2020, 11:00 AM
Prashant Pant
Prashant Pant - avatar
1 Answer
0
since it may be not create the file. check return value of open!!!
21st Jun 2020, 10:39 AM
george
george - avatar