大众信息网

VS2010上C++文件的输入输出问题。

答案:2  mip版
解决时间 2021-04-04 10:01
  • 提问者网友:空气里的回忆
  • 2021-04-03 23:11
我的源程序是这样的:
#include
#include
#include
using namespace std;
int main()
{
ostream outfile("1.dat",ios::out|ios::in);
if(!outfile)
cout<<"open error!"<else
cout<<"open succeed!"<system("pause");
return 0;
}
编译后的错误是这样的:
错误1error C2664: “std::basic_ostream<_Elem,_Traits>::basic_ostream(std::basic_streambuf<_Elem,_Traits> *,bool)”: 不能将参数 1 从“const char [6]”转换为“std::basic_streambuf<_Elem,_Traits> *”h:\c++\test-13\test-13\test-13-2.cpp71test-13
然后我试着把项目的字符集从unicode改为多字符集,还是会出现相同的错误,接着又改了一下源程序,添加了tchar.h头文件:
#include
#include
#include
#include
using namespace std;
int main()
{
ostream outfile(_T("1.dat"),ios::out|ios::in);
if(!outfile)
cout<<"open error!"<else
cout<<"open succeed!"<system("pause");
return 0;
}
可是还是出现相同的问题,我崩溃了,求大神解决!
最佳答案
  • 二级知识专家网友:笑尽沧桑
  • 2021-04-04 00:21
ostream outfile("1.dat",ios::out|ios::in);//改成下面

ostream outfile("1.dat",ios::out);
全部回答
  • 1楼网友:烈酒℃灼言EL
  • 2021-04-04 01:56
我也用vc2010,但不会出这个错误 所给代码,除了最后“retur你0;”原为return 0;之外,没有错误,可以通过编译和运行。 错误原因很可能是在项目设置上的: 建议重新建一个vc->win console的项目,应该能消除这个问题。
我要举报
如以上问答内容为低俗/色情/暴力/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
点此我要举报以上问答信息
推荐资讯