iterators c++ code example
Example 1: c++ vector iterator
vector<string> vData;
vData.push_back("zeroth");
vData.push_back("first");
vData.push_back("second");
vData.push_back("third");
std::vector<string>::iterator itData;
for (itData = vData.begin(); itData != vData.end() ; itData++)
{
auto ElementIndex = itData-vData.begin();
auto ElementValue = vData[ElementIndex];
cout << "[ElementIndex:" << ElementIndex << "][ElementValue:" << ElementValue << "]\n";
}
Example 2: declaring iterator in cpp
vector<int>::iterator ptr;