Have a look at the following code first
By defining a string pointer, this program works the same as defining an iterator. As defining an iterator is more complex than defining a string pointer, why do we need iterator types? I really can't understand. Could somebody be kind enough to tell me? Thanks in advance.Code:#include <vector> #include <iostream> #include <string> using namespace std; int main () { vector<string> text(5, "Hi~"); // empty vector /* for (vector<string>::iterator iter = text.begin(); iter != text.end(); ++iter) { */ /* by defining a string pointer, this program works the same as defining an iterator */ for (string *iter = text.begin(); iter != text.end(); ++iter) { cout<<*iter<<endl; } return 0; }