部分代碼如下
#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++初學者
uj5u.com熱心網友回復:
直接if(!in)就行了uj5u.com熱心網友回復:
if (0 == in)uj5u.com熱心網友回復:
in == 0寫法不對,in是變數?uj5u.com熱心網友回復:
if (!in){
cerr << " 檔案打開錯誤!\n";
exit(1);
}
或
if (!in)
{
cerr << " 檔案打開錯誤!\n";
return 0;
}
uj5u.com熱心網友回復:
ifstream in("player.dat", ios::in);if(in.is_open())
{
}
in 是一個實體,打開檔案流,一般都會成功,這里好象是不成功會有例外(要自行確認). 用 is_open() 方法確認流已打開.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/72746.html
標籤:基礎類
