Question: So I've started learning vectors for the first time and wrote a simple program which goes like this:

```
#include <iostream> 
#include <vector> 
using namespace std; 
int main() 
{ 
    vector<int> g1; 
    int n;
    cout<<"enter values"<<endl;
    do
    {
        cin>>n;
        g1.push_back(n);
    } while (n);
    cout<<"Vector values are: "<<endl;
    for(auto i=g1.begin(); i<g1.size();i++)
    cout<<*i<<endl;
} 

```

When I try executing it, an error shows up saying "type mismatch" at the g1.size() part. Why exactly does this happen? I used the auto keyword for the iterator involved and assumed there wouldn't be any problem?

Answer: 
That is the bad side of using `auto`. If you have no idea what the result of `auto` is, you get no idea why it is something totally different you expect!

`std::vector::begin` delivers a `std::vector::iterator` and you can't compare it against an `size_type` value which is a result of `std::vector::size`. This type is typically `std::size_t`

You have to compare against another iterator which is the representation of the end of the vector like:

```
for(auto i = g1.begin(); i != g1.end(); i++)

```
There are at least three ways to iterate through the contents of a vector.

You can use an index:

```
for (int i = 0; i < vec.size(); ++i)
    std::cout  << vec[i] << '\n';

```

You can use iterators:

```
for (auto it = vec.begin(); it != vec.end(); ++it)
    std::cout << *it << '\n';

```

You can use a range-based for loop:

```
for (auto val : vec)
    std::cout << Val <<'\n';

```

The latter two can be used with any container.