const std::string filename = "C:/Users/z55/Desktop/Model/material.txt";
ifstream infile(filename);
int totalRows = 0;
std::string line;
while (getline(infile, line)) {
++totalRows;
}
ifstream matfile(filename);
std::cout << "totalRows is: " << totalRows << std::endl;
Eigen::MatrixXd matData(totalRows,8);
//
for (int i = 0; i < totalRows; ++i) {
//std::cout << "i = " << i << std::endl;
std::string line;
getline(matfile, line);
......
matData.row(i) = midRow;
iss.clear();
在运行过程中出现了:
abort0 has been called
是因为midRow是空的
代码中使用了两个getline,在这种情况下应注意:
需要在第一个getline后面添加,或其他代码结束这次getline
infile.close();
不关掉文件的话,getline读到回车换行符,再次使用getline时,这行已经没有内容了
398

被折叠的 条评论
为什么被折叠?



