[C++学习记录] abort0 has been called

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时,这行已经没有内容了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值