In C ++ 11, you have three options:
1. Typedef vector instance
typedef std::vector<std::pair<std::string, int>> Vp; Vp v; Vp::iterator i;
2. Use decltype
std::vector<std::pair<std::string, int>> v; decltype(v)::iterator i;
3. Use auto
std::vector<std::pair<std::string, int>> v; auto i = v.begin();
I would say that the third option is the most common, idiomatic use, but they are all valid, and the first option also works in C ++ 98.
source share