'Why does cout writing out nothing?

Im a begginer in c++ and i dont know why this code isnt running. Its writing out nothing... not even the "a"

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<string> allat(N), etel(N);

    for(int a=0;a<N;a++) {
        cin >> allat[N];
        cin >> etel[N];
    }

    int meg=0;

    for(int a=0;a<N;a++) {
        for(int b=0;b<N;b++) {
            if(etel[a] == allat[b]) {
                meg++;
            }
        }
    }



    cout << meg << "a";


Solution 1:[1]

I think the problem is in the following lines:

cin >> allat[N];
cin >> etel[N];

..as these invoke Undefined Behaviour. You should replace N with a, so the above can be replaced by:

cin >> allat[a];
cin >> etel[a];

Now your code should work. Also, look up to why is "using namespace std" considered as a bad practice.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user4581301