previous | start | next

## Reading and Writing Text Files

- Older implementations of the stream library may require a second parameter to open a file.

  >     datafile.open("employee.dat", ios::in | ios::out).

- The file name that you give the `open` command may be a string constant

  >     input_data.open("input.dat");

  or a `string` variable that contains a file name.

  >     string input_name =
  >        cwin.get_string("Please enter the file name:");
  >     ifstream input_data;
  >     input_data.open(input_name);

- Many compilers don't support `string` parameters for the `open` function, so you must use the `c_str` function to convert the parameter to a character array.

  >     input_data.open(input_name.c_str());

- File names can contain directory path information, but you must supply the escape character for a backslash.

  >     input_data.open("c:\\homework\\input.dat");

- Always pass streams by reference!!

previous | start | next