0
File handling problem
Once I write data into the file I want to read the file while reading the file I am not getting the output as well as when I run program There is box come on screen says program stopped Here is the code https://code.sololearn.com/crr3gdXdw757/?ref=app
8 ответов
+ 1
$¢𝐎₹𝔭!𝐨𝓝 first time I run the program without comments which save my data into file.on second run I just want to read the data from the file.the program I mentiond is second time run.but not get me my data
+ 1
Saad Mughal Nice, Thanks for the update.
0
Saad Mughal , You have to create the file which you are trying to open.
Uncomment the below code and check it should work.
ofstream file;
file.open("a.txt",ios::out);
if(!file)
{
cout<<"Error in creating file.."<<endl;
return 0;
}
cout<<"\nFile created successfully."<<endl;
v.SetInsurncePolicy();
v.SetVehicleData();
file.write((char*)&v,sizeof(v));
file.close();
0
Hello Saad Mughal,
Sololearn c++ server deletes all the files created by your executable after execution of your file is finished, So if you run second time due to absence file you are getting the error.
Here I have written a code to print the files and directory present into current working directory before and after the file creation.
If you observe closely for the first time file list is not present and file name is present into the second list. Run file second time and check that file you have created was not there.
https://code.sololearn.com/ctAqQFYG34PP/?ref=app
0
I get the solution and it's not you guys telling me. Its actually Some casting issue i store data as a
String which cause problem while reading.
So I change my string data type members to ch datatype and it's working good. So that's the actual problem
file.write((char*)&v,sizeof(v);
this line have some casting issue
0
$¢𝐎₹𝔭!𝐨𝓝 welcome