C++ examples for File Stream:stream
Flag | Meaning |
---|---|
ios_base::app | Seek to end-of-file before each write. |
ios_base::ate | Seek to end-of-file immediately after opening the file, if it exists. |
ios_base::binary | Open file in binary mode (alternative is text mode). |
ios_base::in | Open file for input (implied for istream). |
ios_base::out | Open file for output (implied for ostream). |
ios_base::trunc | Truncate file, if it exists (default for ostream). |
The following StreamOutput program opens the file MyName.txt and then writes text to that file:
#include <fstream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { ofstream my("MyName.txt"); my << "this is a test\n" << "some text" << endl; /* w w w.ja va 2 s . c o m*/ return 0; }