How to create iterator/s for 2d vector (a vector of vectors)?
Since it's 2020, I'll post an updated and easy method. Works for c++11 and above as of writing.
See the following example, where elements (here: tuples of
tuple find_serial_data( vector >> &serial,
string query)
{
for (auto& i : serial)
{
for (auto& j : i)
{
if ( get<0>(j).compare(query) == 0) return j;
}
}
cout << "\n Not found";
return make_tuple( "", 0);
}
Here is one example without the tuple thing:
string find_serial_data( vector > &serials,
string query)
{
for (auto& i : serials)
{
for (auto& j : i)
{
if ( j.compare(query) == 0) return j;
}
}
cout << "\n Not found";
return "";
}