Hi,
I can't seem to understand why this is not working as expected. The output from the two "couts" are different. Can someone please explain why?
Code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vIntA, vIntB;
for(int a =0; a<6;a++)
{
for(int b=0; b< 5; b++ )
{
vIntA.push_back(a);
vIntB.push_back(b);
cout << "a: " << a << ", b: " << b << "\n";
}
}
for(int a =0; a<6;a++)
{
for(int b=0; b< 5; b++ )
cout << "a: " << a ", vIntA: " << vIntA.at(a) << ", vIntB: " << vIntB.at(b) << "\n";
}
return 0;
}
1st cout:
-a & b work as intended.
2nd cout:
-a & b is ok, as is vIntB. But vIntA is incorrect, mostly with zeros until it accesses 5th element where it's 1's.
What am I missing here?