在STL迭代器中使用`auto`关键字

arc*_*tom 1 c++ iterator stl auto c++11

我正在按照教程使用auto关键字和STL迭代器.

它说这种语法适用于C++ 11.

vector<int> vec;
auto itr = vec.iterator(); // instead of vector<int>::iterator itr
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试它时,我得到这个编译错误?

错误:无效使用'std :: vector :: iterator'

Cal*_*eth 6

该教程是错误的.iterator是所有集合类中的类型成员,而不是函数成员.它是某些成员函数的返回类型vector

本教程可能意味着写的是

vector<int> vec;
auto itr = vec.begin(); // itr is of type std::vector<int>::iterator
Run Code Online (Sandbox Code Playgroud)