c++ - 编译 C++ 代码时出现 ios::nocreate 错误

标签 c++ linux g++ iostream

同时,编译一个包,在 RHEL 5.0 上用 C++ 编写。我收到以下错误。

> 错误:nocreate 不是 std::ios 的成员

源代码对应于:

ifstream tempStr(argv[4],ios::in|ios::nocreate);


我试过了

#g++ -O -Wno-deprecated <file.cpp> -o <file>

还有:

#g++ -O -o <file>

请提出解决方案。

最佳答案

ios::nocreate 不是标准 C++ 的一部分 - 您希望它做什么?

编辑:从谷歌看来,它似乎是为了防止创建文件,如果它不存在的话。无论如何,这是 ifstreams 的默认设置,因此您可以说:

ifstream f( filename );
if ( ! f.is_open() ) {
    // open failed - probably because infput file does not exist  
}

关于c++ - 编译 C++ 代码时出现 ios::nocreate 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1062861/

相关文章:

linux - 如何在 Linux Fedora 中安装 bower?

linux - 使用 bash 获取特定列的总和?

c++ - std::filesystem::copy() 和 std::filesystem::copy_file() 有什么区别?

c++ - 如何使用 C++ 在 Ubuntu 上强制用户注销?

c# - 如何在没有延迟的情况下在 Windows 中重新定位图形?

c++ - 将日期时间转换为毫秒 - C++ - 跨平台

c++ - 如何让 G++ 预处理器在宏中输出换行符?

c++ - 初始化 int 影响函数返回值

linux - 如何安装git lfs

c++ - 确保 g++ 不会使用新版本 C++ 中添加的功能编译程序