Skip to content

Instantly share code, notes, and snippets.

@stevedoyle
Created October 27, 2011 08:47
Show Gist options
  • Save stevedoyle/1319088 to your computer and use it in GitHub Desktop.
Save stevedoyle/1319088 to your computer and use it in GitHub Desktop.
Writing a text file in C++
// 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