程序提示:error C2678: 二进制“==”: 没有找到接受“std::ifstream”类型的左操作数的运算符(或没有可接受的转换)

qq_22984719 2015-07-08 03:47:44
部分代码如下
#include<iostream>
#include<fstream>
#include<iomanip>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<string>
#include"shixun.h"
using namespace std;

//显示错误部分
void chaxun()//读取信息
{

char name[20];
int grade = 0;
int num = 0;
float score;
ifstream in("player.dat", ios::in);
if (in == 0)
{
cerr << " 文件打开错误!\n";
exit(1);
}
cout << "*****************************************************************************" << endl;

cout << setiosflags(ios::right) << setw(10) << "姓名" << setw(15) << "等级" << setw(13) << "答题数量" << setw(10) << "分数" << '\n';

我用VS2013编译后提示
二进制“==”: 没有找到接受“std::ifstream”类型的左操作数的运算符(或没有可接受的转换)
求各位大神解决,我是C++初学者
...全文
3401 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiansk123 2016-08-12
  • 打赏
  • 举报
回复
if (!in) { cerr << " 文件打开错误!\n"; exit(1); } 或 if (!in) { cerr << " 文件打开错误!\n"; return 0; }
tiansk123 2016-08-12
  • 打赏
  • 举报
回复
in == 0写法不对,in是变量?
勉励前行 2016-08-12
  • 打赏
  • 举报
回复
ifstream in("player.dat", ios::in); if(in.is_open()) { } in 是一个实例,打开文件流,一般都会成功,这里好象是不成功会有异常(要自行确认). 用 is_open() 方法确认流已打开.
KT永恒国度 2015-09-08
  • 打赏
  • 举报
回复
直接if(!in)就行了
我不懂电脑 2015-09-08
  • 打赏
  • 举报
回复
if (0 == in)

13,871

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧