Problem with vector function in C ++

0
Hello, I'm trying to make a matrix calculator and my idea would be for the user to enter with the number of rows, columns and soon after with the array elements, the problem is that when I write the elements the program gives error of input stream, if anyone can help me.

SOURCE

#include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main()
{
    int opc;
    int L = 0; //linha
    int C = 0; // coluna
    vector<vector<int>> mat1(L, std::vector<int>(C));
    vector<vector<int>> mat2(L, std::vector<int>(C));
    vector<vector<int>> matResp(L, std::vector<int>(C));

    cout << "1-Sum\n0-Exit\n";
    cin >> opc;

    system("cls");

    switch (opc)
    {
    case 1:
        //soma
        cout << "Enter with number of Lines:\n";
        cin >> L;
        cout << "Enter with number of Coluns:\n";
        cin >> C;

        cout << "Write the elements of Matrix A:\n";

        for (int i = 0; i < L; i++)
        {
            for (int j = 0; j < C; j++)
            {
                cin >> mat1[i][j];
            }
        }

        system("cls");

        cout << "Write the elements of Matrix B:\n";
        for (int i = 0; i < L; i++)
        {
            for (int j = 0; j < C; j++)
            {
                cin >> mat2[i][j];
            }
        }

        system("cls");

        for (int i = 0; i < L; i++)
        {
            for (int j = 0; j < C; j++)
            {
                matResp[i][j] = mat1[i][j] + mat2[i][j];
            }
        }

        for (int i = 0; i < L; i++)
        {
            for (int j = 0; j < C; j++)
            {
                cout << "[ " << matResp[L][C] << " ]";

                if (j == 2)
                    cout << endl;
            }
        }

        cout << endl;

        break;

    case 0:
        break;

    default:
        cout << "Wrong option";
        return main();
    }
}
    
asked by anonymous 02.06.2016 / 17:21

1 answer

1

You are creating the vectors before requesting the size, that is, with 0 rows and 0 columns.

    
19.07.2016 / 13:38