据您所知,在C++中读取文本文件有两个标准(在本例中,每一行有2个数字):
两个标准方法是:
假设每一行由2个数字组成,并按令牌读取令牌:
#include <fstream>
std::ifstream infile("thefile.txt");
int a, b;
while (infile >> a >> b)
{
// process pair (a,b)
}
基于行的解析,使用字符串流:
#include <sstream>
#include <string>
#include <fs