一、需要的头文件
#include <fstream>
#include <sstream>
using namespace std;
二、打开关闭
ifstream file;
file.open(string name,ios::in);
第二个参数默认是ios::in
file.close();
三、读取
为了便于处理,使用字符串流
istringstream stream(string line);
可以使用下面的方式来进行使用:
while(getline(file,line)){
istringstream stream(line);
double a;
while(stream>>a){
cout<<a<<" ";
}
cout<<endl;
}