Created
September 30, 2016 08:20
-
-
Save victorfei/ff7d2568b73c36f6eb50fcd9ce1d64ef to your computer and use it in GitHub Desktop.
A simple C++ snippet for writing to file on disk.
This file contains hidden or 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
| #include <fstream> | |
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| ofstream msgFile; | |
| msgFile.open("msg", ios::out); | |
| // exit program if ifstream could not open file | |
| if (!msgFile) | |
| { | |
| cerr << "File could not be opened" << endl; | |
| exit(EXIT_FAILURE); | |
| } | |
| char msg[11] = {'h', 'e', 'l', 'l', 'o', ' ', 'y', 'o', 'u', '\0'}; | |
| msgFile.write(msg, 11); | |
| msgFile.close(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment