C++ Files
C++ Files
4
Using Input/Output Files
• stream - a sequence of characters
– interactive (iostream)
• cin - input stream associated with keyboard.
• cout - output stream associated with display.
– file (fstream)
• ifstream - defines new input stream (normally
associated with a file).
• ofstream - defines new output stream (normally
associated with a file).
Write/Output to a file
File.txt
1. Create a filestream object and connect the object with the real file name
ofstream outFile("file1.txt", ios::out);
2. Write to data to the filestream object
outFile << " This is a test line!\ n";