previous | start | next

## Random Access

- The follow calls move the get and put positions to character `n` counted from the beginning of the file `fs`.

  >     fs.seekg(n, ios::beg);
  >     fs.seekp(n, ios::beg);

- The second argument can be `ios:end` or `ios::cur` to move the position `n` characters away from the end of the file or the current position, respectively.
- To determine the current position of the get and put positions (counted from the beginning of the file), use

  >     n = fs.tellg();
  >     n = fs.tellp();

- Because the files can be very larger, the positions are long integers.
- To find out the number of characters in a file, move the get position to the end and then find out the distance from the beginning of the file.

  >     fs.seekg(0, ios::end);
  >     long file_length = fs.tellg();

previous | start | next