5
回答
c++文件读写报错class“std::basic_ifstream
华为云4核8G,高性能云服务器,免费试用   

用c++写了段代码,读文件的,但是报错,在网上搜不到问题,哪位以c++高手帮忙看下,谢谢

报错信息:

 error C2079: “file”使用未定义的 class“std::basic_ifstream<_Elem,_Traits>”
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]

以下是代码:环境是vs2012

#include <iostream>
#include <ios>
#include <ostream>
#include <iomanip>
#include <streambuf>
#include <string>
#include <iosfwd>
#include <fstream>
#include <istream>
using namespace std;
class StuService{
public: void Input();
		int Total();
		double Average();

};

void StuService::Input(){
	char buffer[256];
	ifstream file;
	file.open("d://records.txt");
	
	if(!file){
		cout<<"打开records.txt文档异常";
		exit(0);
	}

	int a,b;
	int i=0,j=0;
	
	while(!file.eof()){
		file.getline(buffer,10);
		sscanf(buffer,"%d %d",&a,&b);
		cout<<a<<";"<<b<<endl;
	}
	file.close();
};
int StuService :: Total(){
	return 0;
};
double StuService::Average(){
	return  0.0;
}
void main(){
	StuService service ;
	service.Input();

}



举报
lilitaoa
发帖于5年前 5回/1K+阅
顶部