按行读取txt中文件
#include<fstream>
#include<iomanip>
using namespace std;
std::ifstream Infile;
std::locale::global(std::locale(""));//是为了保证,支持中文的路径。
string strLine;
Infile.open("D:/name.txt");
std::locale::global(std::locale("C"));//设置
while (Infile)
{
getline(Infile, strLine);
if (strLine.empty())
break;
}
把读取的每行数据进行处理
name.txt
xiaoming 0 80 75 88 66
while (Infile)
{
getline(Infile, strLine);
if (strLine.empty())
break;
stringstream strin(strLine);
Unit struFeat;
int Id = 0;
string strName;
strin >> strName;
strin >> Id;
int fScore;
int inum = 0;
while (strin >> fScore)
{
struFeat.vecFeat[inum] = fScore;
inum++;
}
}