Write your question here.
I typed this program as it is in the textbook by Walter Savitch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
Put the code you need help with here.
//Program to demonstrate STL iterators
#include<iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
using std::vector<int>::iterator;
int main() {
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";
*p = 0;
cout << "Container now contains:\n";
for (p = container.begin(); p != container.end(); p++)
cout << *p << " ";
cout << endl;
return 0;
}
|
When I compile I get this error:
8 25 C:\Dev-Cpp\SavitchChapter18\IteratorVector.cpp [Error] 'std::vector<int>' is not a namespace
C:\Dev-Cpp\SavitchChapter18\IteratorVector.cpp In function 'int main()':
18 2 C:\Dev-Cpp\SavitchChapter18\IteratorVector.cpp [Error] 'iterator' was not declared in this scope
18 2 C:\Dev-Cpp\SavitchChapter18\IteratorVector.cpp [Note] suggested alternatives:
65 0 c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\stl_algobase.h In file included from c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\stl_algobase.h
39 c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\char_traits.h from c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\char_traits.h
40 c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\ios from c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\ios
38 c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\ostream from c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\ostream
39 c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\iostream from c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\iostream
2 C:\Dev-Cpp\SavitchChapter18\IteratorVector.cpp from C:\Dev-Cpp\SavitchChapter18\IteratorVector.cpp
118 12 c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\stl_iterator_base_types.h [Note] 'std::iterator'
118 12 c:\program files\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\stl_iterator_base_types.h [Note] 'std::iterator'
18 11 C:\Dev-Cpp\SavitchChapter18\IteratorVector.cpp [Error] expected ';' before 'p'
19 7 C:\Dev-Cpp\SavitchChapter18\IteratorVector.cpp [Error] 'p' was not declared in this scope