#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
double temp1, temp2;
string input;
ifstream fin;
bool error;
fin.open("in.txt");
error=false;
while (true)
{
getline(fin,input);
if (!fin) break; //check for eof
istringstream buffer(input);
buffer >> temp1 >> temp2;
//check for non numerical input
//and less/more input than needed
if (!buffer || !buffer.eof())
{
error=true;
break;
}
//do what you want with temp1 and temp2
cout << temp1 << '\t' << temp2 << endl;
}
if (error)
cout << "file is corrupted..." << endl;
cout << "hit enter to quit...";
cin.get();
return 0;
}
C++ 按行读取数据文件,每行以tab分隔
最新推荐文章于 2024-05-16 16:18:47 发布