Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ios::Nocreate flag results in "undeclared identifier" error [duplicate]

Tags:

c++

fstream

Possible Duplicate:
ios::nocreate error while compiling a C++ code

i have been working on how to create a simple lexical compiler in c++/c# but it seems i have a an error when i try to compile the program the error is

error c2065 'nocreate' undeclared identifier 

how can i handle this problem??but im thinking maybe it has to do with the fstream header,any ideas on how i can handle it??

this is the code where it is giving me an error

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);
like image 864
user1806672 Avatar asked Nov 13 '12 10:11

user1806672


2 Answers

ios::Nocreate is not part of standard C++, but if the intention is to prevent the file being created if it doesn't already exist, you can relax. This is the default for ifstreams anyway, so you can just say:

fstream File("input.txt", ios::in);
like image 104
Josh Avatar answered Sep 19 '22 19:09

Josh


If you are with VisualStudio, try

std::fstream File("input.txt", std::ios::in|std::ios::_Nocreate);
like image 29
billz Avatar answered Sep 16 '22 19:09

billz