Chachmu
Chachmu

Reputation: 8192

C++ Vector giving incredibly unexpected value

I have this code:

std::vector <int> loc;
loc.push_back(cpx);
loc.push_back(cpy);
loc.push_back(play.GetSize().x);
loc.push_back(70);
std::cout<<loc[3];

in a game I am making but even when I print the value of loc[2] and loc[3] they are completely different than they should be, when I run this code I get loc[3] equaling 70070 instead of 70. Does anybody know how to fix this?

Upvotes: 2

Views: 147

Answers (1)

us2012
us2012

Reputation: 16253

You have another cout without an endl or \n somewhere in your code that you forgot to remove. That one prints the 700, while the 70 is the correct output of the last line in your code sample.

Change your last line to std::cout<< " and loc[3] is: " << loc[3] << std::endl; to see that my wild guess is right, then go hunting for that other cout.

Upvotes: 9

Related Questions