Created
October 27, 2011 08:47
-
-
Save stevedoyle/1319088 to your computer and use it in GitHub Desktop.
Writing a text file in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from: http://www.cplusplus.com/doc/tutorial/files/ | |
// writing 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment