change a file by offset : fstream « File Stream « C++ Tutorial






#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[])
{

  fstream out("test.txt", ios::in | ios::out | ios::binary);
  if(!out) {
    cout << "Cannot open file.";
    return 1;
  }

  out.seekp(12, ios::beg);

  out.put('a');
  out.close();

  return 0;
}








12.8.fstream
12.8.1.Open a file for output then write to that file
12.8.2.Reverse a file
12.8.3.Use fstream to read and write a file.
12.8.4.change a file by offset