previous | start | next

## Reading and Writing Text Files

- Writing to a file is similar.
- Open a file for writing.

  >     ofstream output_data;
  >     output_data.open("output.dat");

- Send information to the file in the usual way.

  >     output_data << n << " " << x << "\n";

- To write a single character to a file use

  >     output_data.put(ch);

- When you are done, remember to close the file.

  >     output_data.close();

previous | start | next