+ 1
File in c++
This code is a in cpp Can someone explain it to me please? fstream fp("courses.dat" , ios::out|ios::in|ios::binary); if(!fp) { ofstream fp1("courses.dat" , ios::out|ios::binary); fp1.close(); } ifstream inj("j.txt" , ios::in); if(!inj) { ofstream outj("j.txt" , ios::out); int tempJ=0; outj<<tempJ; outj.close(); }
5 Answers
+ 1
Myabe this can help you:
https://www.sololearn.com/learn/CPlusPlus/1920/
https://www.sololearn.com/learn/CPlusPlus/1921/
If not, tell us where you dont inderstand what is happening
0
Alexander Thiem
tnx Alexander Thiem those informations helped me a little
But i still have questions
First :can we write" if(inj.is_open())" instead of (!inj)? And if the answer is no can you explain me why?
And the second question is why we use flag ios::in ? I really don't understand the usage of these optional parameters (flags)
Sorry I'm new to cpp so I have so many questions
0
I think inj.is_open is similar to !inj, but you can probably test this out in code playground or an other code area.
In this case the file is opened with ios::in , which means that you can only read it....
These flags define how the file is open:
For example ios::trunc clears the file completely before opening it.
Hope I could help you
0
Alexander Thiem
Tnx for your help
0
you are welcome