# having problem compiling example in "Problem Solving in C++" book



## lockfile (Oct 6, 2012)

I typed it in word with the intent to later modify and play around with the code, but I cannot get it to complile using GCC. Any pointers?

Error received is:

```
ione.cpp:19: error: â€˜iteratorâ€™ was not declared in this scope
```

Makefile:

```
ione : ione.cpp
	g++ -o ione ione.cpp
```


```
#include <iostream>
#include <cstdlib>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
using std::vector<int>::iterator;


int main( int argc, char* argv[] ) 
{
  vector<int> container;

  for (int i = 1; i <= 4; i++)
    container.push_back(i);

  cout << "Here is what is in the container: \n";

  iterator p;
  for (p = container.begin(); p != container.end(); p++)
    cout << *p << " ";
  cout << endl;

  cout << "Setting entries to 0:\n";
  for (p= container.begin(); p != container.end(); p++)
    *p = 0;

  cout << "Container now contains:\n";
  for (p = container.begin(); p != container.end(); p++)
    cout << *p << " ";

  exit(0);
}
```


----------



## lockfile (Oct 6, 2012)

Hey I'm on gcc 4.4.4. I think that this could be a version issue. I typed it into the book, and the library on my system does not contain the 
	
	



```
std::vector<int>::iterator
```
 class for me to use is my guess.


----------



## kpa (Oct 6, 2012)

The using std::vector<int>::iterator; line is not valid c++ because the template can't be instantiated (I think that's the term, I haven't used c++ in a while) in a using declaration. It's also not needed because the previous line already brings in the needed definition of the iterator.

Change the line with 

```
iterator p;
```

To:

```
vector<int>::iterator p;
```


----------



## lockfile (Oct 20, 2012)

Thank you. The reason I had it like that is because the book had it written like that. Programming with compiled languages involves many caveats.


----------

