Reputation:
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";
Upvotes: 0
Views: 135
Reputation: 1595
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.
Upvotes: 3