我試圖給多維向量賦值,但我總是從visual studio中得到「R6010 - abort()」錯誤。將值賦給多維向量
我想要的是一個二維矢量,其中第二維完全像需要一樣大。 (重要,因爲我不知道我現在想要多少輸入值和使用後myvector.at(i).size();
所以制定簡短:爲什麼不工作下面的例子
#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector < vector <int> > Vektor;
Vektor.resize(10);
int tmp;
while (true) {
cout << "Please enter a value: " << endl;
cin >> tmp;
int size;
if (tmp > 0 & tmp < 11) {
Vektor.at(tmp - 1).push_back(tmp);
}
for (int i = 1; i < 11; i++) {
size = Vektor.at(i).size();
for (int j = 0; j < size; j++) {
cout << "Value at " << i << " , " << j << " : " << Vektor.at(i).at(j) << endl;
}
}
}
return 0;
}
它應該告訴你這個錯誤發生在哪裏。無論如何,你應該使用一個調試器。 –