C++ examples for File Stream:stream
Mode | Description |
---|---|
app | Open the file for appending (adding to it). |
ate | Seek to end of file on opening it. |
in | Open the file for reading. |
out | Open the file for writing. |
binary | Open the file in binary mode. |
trunc | Discard contents if file exists |
nocreate | If file doesn't exist, open fails. |
noreplace | If file exists, open fails unless appending or seeking to end of file on opening. |
Writes five names to a disk file in Binary Modes.
#include <fstream> #include <iostream> using namespace std; ofstream fp;/*from w w w . j a va 2s.com*/ void main() { fp.open("NAMES.DAT", ios::out); // Creates a new file. fp << "Michael Langston\n"; fp << "Sally Redding\n"; fp << "Jane Kirk\n"; fp << "Stacy Wikert\n"; fp << "Joe Hiquet\n"; fp.close(); // Release the file. return; }