使用ios :: Nocreate标志会导致"未声明的标识符"错误

use*_*672 5 c++ fstream

可能重复:
编译C++代码时出现ios :: nocreate错误

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

error c2065 'nocreate' undeclared identifier 
Run Code Online (Sandbox Code Playgroud)

我怎么能处理这个问题??但我想也许它与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);
Run Code Online (Sandbox Code Playgroud)

Jos*_*osh 10

ios::Nocreate不是标准C++的一部分,但如果目的是阻止文件创建(如果它尚不存在),您可以放松.这是ifstreams的默认值,所以你可以说:

fstream File("input.txt", ios::in);
Run Code Online (Sandbox Code Playgroud)


bil*_*llz 4

如果您使用 VisualStudio,请尝试

std::fstream File("input.txt", std::ios::in|std::ios::_Nocreate);
Run Code Online (Sandbox Code Playgroud)