c++ - Interesting output by iteration -


explanation of why garbage happens & number of garbage occur.

#include <vector> #include <iostream>  using namespace std;  int main() {     vector<int> v1;     vector<int> v2;      for(int i=0 ; < 10 ; i++)         v1.push_back(i);      for(int i=11 ; <= 20 ; i++)         v2.push_back(i);      for(vector<int>::iterator = v1.begin() ; != v2.end() ; it++)         cout << *it << " ";      return 0; } 

you iterate on vector v1 , prove iterator against v2.end. that's wrong. correction:

for (vector<int>::iterator = v1.begin() ; != v1.end() ; it++)      cout << *it << " "; 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -