Hey everyone, I have just started to learn C++ and I wanted to know how to read and write to a text file. I have seen many examples but they have all been hard to understand
To read you should create an instance of ifsteam and not ofstream.
ifstream iusrfile;
You should open the file in read mode.
iusrfile.open("usrfile.txt", ifstream::in);
Also this statement is not correct.
cout<
If you are trying to print the data you read from the file you should do:
cout<
You can read more about ifstream and its API here