Skip to content

Instantly share code, notes, and snippets.

@shaina7837
Created July 22, 2013 07:37
Show Gist options
  • Save shaina7837/6051970 to your computer and use it in GitHub Desktop.
Save shaina7837/6051970 to your computer and use it in GitHub Desktop.
output is: Input some numbers and then end the input 3 4 5 end if I use 1st simple for loop, output is 5 if use 2nd one range for loop output is 5 5 5 why ?
#include <iostream>
#include <vector>
using namespace std;
main()
{
vector<int> v;
int number;
auto c = 0;
cout <<"Input some numbers and then end the input\n";
while(cin>>number){
v.push_back(number);
c++;
}
//for(i = 0; i < c; i++)
for(auto i : v)
cout << v.at(2) << " ";
cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment