ofstream open出错

来源:互联网 发布:utf8与gbk相互转换java 编辑:程序博客网 时间:2024/06/08 06:43
INT CWriteFileBase::OpenCsvFile(ofstream& of, const CString& strLogFile){of.open(strLogFile, std::ofstream::app);if (!of){return RET_ERR;}return RET_OK;}

如果已经of.open了没有关闭,再执行of.open会失败。即open时候文件是没有被打开的。

附:

void open ( const char * filename,
  ios_base::openmode mode = ios_base::in | ios_base::out );
  

Open file

Opens a file whose name is s, associating its content with the stream object to perform input/output operations on it. The operations allowed and some operating details depend on parameter mode.

The function effectively calls rdbuf()->open(filename,mode).

If the object already has a file associated (open), the function fails.

On failure, the failbit flag is set (which can be checked with member fail), and depending on the value set with exceptions an exception may be thrown.

原创粉丝点击