Revision: 34291
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 20, 2010 16:18 by browny
Initial Code
// writing on a text file #include <iostream> #include <fstream> using namespace std; int main () { ofstream myfile ("example.txt"); if (myfile.is_open()) { myfile << "This is a line.\n"; myfile << "This is another line.\n"; myfile.close(); } else cout << "Unable to open file"; return 0; } // reading a text file #include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; ifstream myfile ("example.txt"); if (myfile.is_open()) { while ( myfile.good() ) { getline (myfile,line); cout << line << endl; } myfile.close(); } else cout << "Unable to open file"; return 0; }
Initial URL
http://www.cplusplus.com/doc/tutorial/files/
Initial Description
Initial Title
Input/Output with files
Initial Tags
file
Initial Language
C++