在C++中,我们经常需要检查文件是否存在。在旧版本的C++中,可以使用以下代码来检查文件是否存在:文
static const WORD MODEL_OUT = std::ios::out; // 0x02, for writing, the file does not exist, to create, if the file already exists, clear the original content (ofstream default Open) static const WORD MODEL_ATE = std::ios::ate; // 0x04, when the file is opened, the pointer in...
(b) The only way I know in C++ to check if a file exists is to open the file for reading [only] and check whether it succeeds. My guess is that if it doesn't succeed (there is no such file), then you re-open the stream for writing and continue using it (if I understood your...
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
(filename.c_str(),ios::in);// open the fileif(inFile.fail())// check for successful open{ cout << filename <<" was not successfully opened\n Please check that the file currently exists."<< endl; exit(1); } cout <<"\nThe file has been successfully opened for reading.\n";...