我正在尝试编写一个程序来读取任意逗号分隔的矩阵,然后将矩阵打印到屏幕上。我的程序如下所示。当我尝试运行程序时,我收到错误消息'Debug Error!... R6010 -abort()已被调用'或类似的东西。我觉得这可能是程序如何构建的问题,因为下面的同一程序在不同的编译器上工作。我正在使用visual studio 2013.我对这个软件的经验很少,所以我很感激你的回答。即使我在没有调试的情况下启动程序,我仍然会收到此错误。
//includes
#include<string>
#include<vector>
#include<fstream>
#include<iostream>
using namespace std;
//main programme begins here
int main() {
//define vectors to read matrix into
vector <vector<double>> Matrix;
string aLine, element;
//openfile
ifstream InputMatrix("inputmatrix.txt");
while (!InputMatrix.eof()) {
getline(InputMatrix, aLine);
size_t commapos = 0;
vector <double> across;
while (commapos != string::npos) {
commapos = aLine.find(',', 0);
string element = aLine.substr(0, commapos);
aLine = aLine.substr(commapos + 1, aLine.length() - commapos - 1);
across.push_back(stod(element));
}
Matrix.push_back(across);
}
InputMatrix.close(); //closes file
//check file has read in correctly
int i, j;
for (i = 0; i < Matrix.size(); i++) {
for (j = 0; j < Matrix[i].size(); j++) {
cout << Matrix[i][j] << ", ";
}
cout << "\n ";
}
return 0;
}