Message from C, C++ talks

June 2019

— You*

— FILE* file = fopen( ... );

— You also need to check if the file was opened actually

— And only after that you can read from it

— 

It is working fine now
void account::read_data(){
FILE *file;
file = fopen("C:\\cfiles\\count.txt","r");
if(!file){
cout << "error\n";
}
int ch;
fscanf(file,"%d",&ch);
cout << ch << "\n";
ch = ch+1;
cout << ch << "\n";
fputc(ch,file);
fclose(file);

— Thank you :)

— I forgot i had changed the location of file🤦🏻‍♂️

— This will crash if the file wasn't opened

— Yup, thanks for help :)

— Why do you use C fopen if you are using C++?

— Cause i don't know how to read int from c++ style files😅

— Fstream filee("c:\\cfiles\\bankrecord.txt",ios::in|ios::out|ios::app);
if(!filee.is_open()){
cout << "error in opening file\n";
}
filee << ch << " Record\n";
filee << "Account holder name: " << name <<"\n";
filee << "Account number: " << acno <<"\n";
filee << "Amount: " << amount << "\n";
filee << "End\n";
cout << "File saved succesfully\n";
filee.close();

YOU MEAN THIS ?

Message permanent page

— Yeah but reading from there using streams

— Ok will try

— 😁