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++标准中去掉了对它的支持。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值