c++ for iterator code example
Example 1: c++ array interator
#include <array>
#include <vector>
#include <iterator>
int main()
{
int c_array[5] = {};
std::array<int, 5> cpp_array = {};
std::vector<int> cpp_dynarray(5);
auto c_array_begin = std::begin(c_array);
auto c_array_end = std::end(c_array);
auto cpp_array_begin = std::begin(cpp_array);
auto cpp_array_end = std::end(cpp_array);
auto cpp_dynarray_begin = std::begin(cpp_dynarray);
auto cpp_dynarray_end = std::end(cpp_dynarray);
}
Example 2: 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";
}