Example program for file updating random access
Also, the is_open() function will return true if the stream is currently open, and false otherwise.
A warning about writing pointers to disk While streaming variables to a file is quite easy, things become more complicated when you’re dealing with pointers.
The first parameter is an offset that determines how many bytes to move the file pointer.
The second parameter is an Ios flag that specifies what the offset parameter should be offset from.
Remember that a pointer simply holds the address of the variable it is pointing to.
However, it is also possible to do random file access -- that is, skip around to various points in the file to read its contents.For some types of streams, seekg() (changing the read position) and seekp() (changing the write position) operate independently -- however, with file streams, the read and write position are always identical, so seekg and seekp can be used interchangeably.The seekg() and seekp() functions take two parameters.Note: Some compilers have buggy implementations of seekg() and seekp() when used in conjunction with text files (due to buffering).If your compiler is one of them (and you’ll know because your output will differ from the above), you can try opening the file in binary mode instead: which is how long is in bytes (assuming a carriage return after the last line).