void open (const char* filename, ios_base::openmode mode = ios_base::in | ios_base::out);
void open (const char* filename, ios_base::openmode mode = ios_base::in | ios_base::out);void open (const string& filename, ios_base::openmode mode = ios_base::in | ios_base::out);
rdbuf()->open(filename,mode) | member constant | stands for | access |
|---|---|---|
| in | input | File open for reading: the internal stream buffer supports input operations. |
| out | output | File open for writing: the internal stream buffer supports output operations. |
| binary | binary | Operations are performed in binary mode rather than text. |
| ate | at end | The output position starts at the end of the file. |
| app | append | All output operations happen at the end of the file, appending to its existing contents. |
| trunc | truncate | Any contents that existed in the file before it is open are discarded. |
|).1
2
3
4
5
6
7
8
9
10
11
12
13
14
// fstream::open / fstream::close
#include <fstream> // std::fstream
int main () {
std::fstream fs;
fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);
fs << " more lorem ipsum";
fs.close();
return 0;
}