时间:2021-03-24 10:28:58 | 栏目:C代码 | 点击:次
如下所示:
#include <iostream> #include <fstream> #include <sstream> #include <string> using namespace std; int main(){ cout << "input the file name: "; string file_name; cin >> file_name; cout << endl; // ifstream infile("1.txt"); ifstream infile(file_name.c_str()); string line; while (std::getline(infile, line)){ std::istringstream iss(line); int a, b; if (!(iss >> a >> b)) { break; } // error cout << "a : " << a << endl; cout << "b : " << b << endl; } return 1; }