File I/O Basics
Need to provide the necessary information first:
Declaration:
- ifstream in_stream;
- ofstream out_stream;
Opening: note the dot (i.e. a period) and that the file name is given in quotes
- in_stream.open(“infile.dat”);
- out_stream.open(“outfile.dat”);
Now you can use the extraction operator >> or insertion operator << to read and write
- in_stream >> one_number >> another_number;
- out_stream << one_number << another_number;
Closing:
- in_stream.close();
- out_stream.close();