Вызвано исключение: нарушение доступа для чтения. this было 0xFDFDFDFD

Имеется код:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>   
#include <fstream>
#include <stack>
int main()
{
    std::ofstream fout("output.txt");
    std::ifstream fin("input.txt");
    int N, K, P;
    fin >> N >> K >> P;
    int max = 0;
    int current = 0;
    bool error = false;
    char command;
    int num, fuel, temp;
    std::stack<int> **barge = new std::stack<int>*[K];
    for (int i = 0; i < K; ++i)
    {
        barge[i] = new std::stack<int>;
    }
    for (int i = 0; i < N && !error; ++i)
    {
        fin >> command >> num >> fuel;
        if (command == '+')
        {
            barge[num]->push(fuel);
            current++;
            if (barge[num]->size() > P)
            {
                error = true;
                break;
            }
            if (current > max)
                max = current;
        }
        else if (command == '-')
        {
            if (barge[num]->size() == 0)
            {
                error = true;
                break;
            }
            temp = barge[num]->top();
            barge[num]->pop();
            current--;
            if (temp != fuel)
            {
                error = true;
                break;
            }
        }
    }
    for (int i = 0; i < K; ++i)
    {
        delete barge[i];
    }
    delete[] barge;
    if (error || current > 0)
        fout << "Error";
    else
        fout << max;
    return 0;
}

В visual studio 2017 выдает "Вызвано исключение: нарушение доступа для чтения. this было 0xFDFDFDFD". Не пойму что не так.


Ответы (0 шт):