C++多行文本读取
使用的多行讀取的代碼如下:
//讀取文本浮點(diǎn)數(shù)到多個(gè)模式 序列
bool CPicToolsDlg::readTxt2SeqMulti(std::string TxtName, std::vector<std::vector<float > > &Seq )
{//三元組,使用三元組逐個(gè)寫(xiě)入float ViewValue,ViewValue2,ViewValue3; Seq.resize(0);std::string TestTxt(TxtName); // std::ifstream ifs;std::vector<std::string> vec;std::string line;int IdxLine = 0;ifs.open(TestTxt.c_str() );if (!ifs.rdbuf()->is_open()){printf("Error in open file %s\n", TestTxt.c_str());return false;}else{while(getline(ifs,line))//循環(huán)取出每一行數(shù)據(jù){std::vector<float > Vline(0);std::istringstream stream(line);while( stream>> ViewValue)//將一行的多個(gè)字段取出{//對(duì)一行中的每個(gè)字段進(jìn)行處理Vline.push_back(ViewValue);}//++IdxLine;Seq.push_back(Vline);}}ifs.close();return true;
}
總結(jié)
- 上一篇: 旺影速转如何转换视频格式?旺影速转转换视
- 下一篇: 电脑打印机出现0×8007007e错误怎