天天看點

error C2065: 'nocreate' : undeclared identifier

In addition to the above changes, the following functions, constants, and enumerators that are elements of the old iostream library are not elements of the new iostream library:

  • attach member function of filebuf, fstream ifstream, and ofstream
  • fd member function of filebuf, fstream ifstream, and ofstream
  • filebuf::openprot
  • filebuf::setmode
  • ios::bitalloc
  • ios::nocreate
  • ios::noreplace
  • ios::sync_with_stdio
  • streambuf::out_waiting
  • streambuf::setbuf (use rdbuf -> pubsetbuf for the same behavior)

what's the .net replacement for ios::nocreate

"John Harrison" <> wrote in message news:<>...

> > In the new VC++ 7.0 ios::nocreate is obsolete. Does any one know what

> > I should do to achieve the same goal? I really want to check if a

> > file exists before reading from it.

> >

>

> There is no need for nocreate. If you open a file for reading and the file

> doesn't exist, then the open will fail. Nocreate is the default if you like.

是以不用nocreate也是可以的

在C++中

#include <fstream>

#include <iostream>

using namespace std;

使用ios::nocreate會報告錯誤:

error C2039: 'nocreate' : is not a member of 'basic_ios<char,struct std::char_traits<char> >'

error C2065: 'nocreate' : undeclared identifier

執行 cl.exe 時出錯.

在C中

#include<fstream.h>  

#include<stdlib.h>

可以直接使用

原因在于

ios::nocreate是在C++标準制定之前在<fstream.h>中有定義的。但是因為它跟系統平台相關密切,是以在C++标準中去掉了對它的支援。