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++標準中去掉了對它的支持。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章