【问题标题】:Using ios::Nocreate flag results in "undeclared identifier" error [duplicate]使用 ios::Nocreate 标志会导致“未声明的标识符”错误 [重复]
【发布时间】:2012-11-13 10:13:25
【问题描述】:

可能重复:
ios::nocreate error while compiling a C++ code

我一直在研究如何在 c++/c# 中创建一个简单的词法编译器,但是当我尝试编译程序时似乎出现了错误

error c2065 'nocreate' undeclared identifier 

我该如何处理这个问题??但我想它可能与 fstream 标头有关,关于我如何处理它的任何想法??

这是它给我一个错误的代码

loadTransitionTable( );

    fstream File("input.txt", ios::in|ios::Nocreate);

    if (!File)
    {
       cout<<"\n Unable to open the input file."<<endl;
       cout<<"\n Press any key to exit.";

       getch( );
       exit(0);

【问题讨论】:

标签: c++ fstream


【解决方案1】:

ios::Nocreate 不是标准 C++ 的一部分,但如果目的是阻止创建不存在的文件,您可以放松。无论如何,这是 ifstreams 的默认设置,所以你可以说:

fstream File("input.txt", ios::in);

【讨论】:

    【解决方案2】:

    如果您使用 VisualStudio,请尝试

    std::fstream File("input.txt", std::ios::in|std::ios::_Nocreate);
    

    【讨论】:

      【解决方案3】:

      标准 c++ 库没有定义 std::ios::Nocreate。无论如何都不会创建打开以供阅读的文件,因此您可以将其省略:

      fstream File("input.txt", ios::in);

      或者直接使用:

      ifstream File("input.txt");

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-07
        • 2014-08-04
        相关资源
        最近更新 更多