Question : Help me understand the usefulness of the pair function.

I want to learn about and understand the pair function in C++.  Please illustrate for me or show me an easy tutorial that I can read that will help me understand why we use pair.  Also, please explain what .second does....Thanks.

ultimately, i want to be able to understand what is going on in the attached code, line-by-line...thanks.
1:
2:
3:
4:
5:
6:
set<int> sAlreadyAccountedFor;

 pair<set<int>::iterator, bool> p = sAlreadyAccountedFor.insert(i->csStudentIDs);

 if (p.second)
{......

Answer : Help me understand the usefulness of the pair function.

>>is it true when we are ABLE to successfully insert i->csStudentIDs into the
>>set?

If the docs are correct: yes ;o)

>>and, are we able to successfully insert i->csStudentIDs into the set ONLY
>>because it wasn't there prior to the insertion?

Correct.

>>and, if the value of i->csStudentIDs already happened to be in the set prior
>>to insertion the bool would be FALSE?

Also correct - that's the whole purpose of this setup. It's way better than haveing e.g. a list or a vector of elements that have already been processed and manually search them.
Random Solutions  
 
programming4us programming4us