After reading through most of the maps
questions, I eventually got an idea from this link: How to unique my data that are stored in an object which are stored in a vector?
I have a task of storing X
, Y
, Z
coordinates from the user input. To prevent the user from entering duplicated data, I have decided to use map containers as they do not allow duplicated data.
I tested the code out.
I am using X
as the key
and Y as the value
I am able to store X
and Y
via this:
map<int, int> mapp2d;
mapp2d.insert(pair<int, int>(X, Y));
And to access them via this:
map<int, int>::iterator p = mapp2d.begin();
map<int, int>::iterator e = mapp2d.end();
while ( p != mapp2d.end())
{
cout << "X: " << p->first << " Y: " << p->second << endl;
p++;
}
Is it possible to do it for X
, Y
, Z
? Like this:
map<int, int, int> mapp3d
mapp3d.insert(pair<int, int, int>(X, Y, Z))
I tested out the code but i got this errors:
error: wrong number of template arguments (3, should be 2)
error: provided for ‘template<class _T1, class _T2> struct std::pair
Yes, i do know it is illegal for me to do that, but there're no tutorials on how should i do so, and i kind of ran out of ideas, and how can i access them ?
Appreciate you guys for taking a look, thanks in advance.