首页 > 编程知识 正文

C语言读取txt文件中的矩阵,C语言读取txt文件,转换成程序

时间:2023-05-03 12:20:35 阅读:202360 作者:2962

按行读取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++;}}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。