Both work(no error),and the result are exact the same :|
In file.txt is written "abcdefgh12345678",and after compiling,is written: [NUL][NUL][NUL][NUL][NUL]write.
I would be happy for any response :)
Thank you,and Merry Christmas !
Creates an output file that is blank so you will always create a blank file and then move forward 5 and write on the sixth space. Since you never created values for the data positions before where you placed the cursor the [nul] is not at all unexpected.
If you were wanted to write to the file but not create a blank document I think you need to use
f.seekg(5); // move the "get" position forward
f<<"write"; // write at the "put" position
This writes at the 6th positions, because file streams have only ONE position. Both reading and writing happen there. That's a limitation of the C file I/O, which C++ file I/O is implemented in terms of.
Other C++ streams (stringstream for example) have two independent positions: one for reading, one for writing. If f is a stringstream, your f<<"write" will write starting at the first position, where the put pointer is.