I'm practicing file handling. I made a text file and wrote some characters in it, now I want the cursor to go to the beginning of the file and put a character there using seekp.
Here is the code
fstream ofile;
char ch = 'g';
ofile.open("test.txt", ios::out | ios::app);
ofile.seekp(0, ios::beg);
ofile.put(ch);
ofile.close();
Expected Result: It writes g at the start of file.
Actual Result: It appends g at the end.
I tried removing the ios::app tag but ios::out alone truncates the file before writing anything.