Flag Function
最近用到了C++输入输出流操作,所以顺手记了下来。以后再慢慢补充
ofstream(默认是ios::in | ios::trunc)、ifstream(默认是ios::in)、fstream(默认是ios::in | ios::out)不同的流对应操作不一样
ios::app Opens an output file for appending.
//如果没有文件则创建文件并将所有输出附加在文件末尾,如果有文件则将所有输出附加在文件末尾
//可以用ofstream、fstream流打开
// Add the code from here
ofstream DepthInfo;
TComDataCU* DepthCU = m_ppcBestCU[0];
DepthInfo.open("BestDepth.txt", ios::app);
for (UInt iPartitionNum = 0; iPartitionNum < DepthCU->getTotalNumPart(); iPartitionNum++)
{
int DepthCUT = 0;
DepthCUT = DepthCU->getDepth(iPartitionNum);
DepthInfo << DepthCUT;
cout << DepthCUT << endl;
}
DepthInfo.close();
ios::ate
Opens an existing file (either input or output) and seeks the end.
//打开一个现有文件(输入或输出)并寻找结束(默认以读的方式打开文件)。
//可以用ofstream、fstream流打开
ios::in
Opens an input file. Use ios::in as an open_mode for an ofstream file to prevent truncating an existing file.
//打开输入文件。将ios::作为ofstream文件的open_mode使用,以防止截断现有文件。
//没有文件的话则打开失败
//可以用ifstream、fstream打开
ios::out
Opens an output file. When you use ios::out for an ofstream object without ios::app, ios::ate, or ios::in, ios::trunc is implied.
//打开输出文件。当您使用ios::out来处理一个没有ios::app、ios::ate或ios::in的ofstream对象时,会隐含ios::trunc。
//可以用ofstream、fstream流打开
ios::nocreate
Opens a file only if it already exists; otherwise the operation fails.
//仅当文件已经存在时才打开该文件;否则操作失败。
ios::noreplace
Opens a file only if it does not exist; otherwise the operation fails.
//仅当文件不存在时才打开该文件;否则操作失败。
ios::trunc
Opens a file and deletes the old file (if it already exists).
//打开一个文件并删除旧文件(如果它已经存在)。
ios::binary
Opens a file in binary mode (default is text mode).
//以二进制模式打开文件(默认为文本模式)。
推荐一个写的比较全面的:c++进阶—IO类详解(二)–文件流的详解。