C ++输入循环给出" Process完成退出代码11"错误

时间:2015-08-21 23:27:44

标签: c++ arrays multidimensional-array clion

以下是我的C ++代码的开头。我希望能够键入5个输入并将它们存储在向量中。但是,代码在双数组元素访问中断。我该如何解决这个问题,为什么会破坏?我在IDE(CLion)上遇到的错误是"找不到运算符[]"。

#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;

using std::sort;
using std::streamsize;
using std::string;
using std::vector;

int main () {
    vector<int> inputVec;
    int x;
    while (cin >> x && inputVec.size() < 5) {
        inputVec.push_back(x);
        cout << inputVec.size() << endl;
    }
    sort(inputVec.begin(), inputVec.end());
    cout << "before if 1" << endl;
    typedef vector<double>::size_type vec_sz;
    vec_sz size = inputVec.size();
    cout << "before if 3" << endl;
    if (size < 4) {
        cout << "too few inputs";
    } else {
        cout << "calculating quartiles" << endl;
        int quartileSize = size / 4;
        int leftOvers = size - quartileSize * 4;
        int count = 0;
        vector<vector<int>> quartiles(4);
        for (int i = 0; i < 3; i++) {
            for (int j = 0; i < quartileSize; j++) {
                quartiles[i][j] = inputVec[count++];
            }
        }

0 个答案:

没有答案