Hi everyone,
I have a std::map of structures . I'm reading the data from a file named "auxIdSorted.txt" and I need to do a while() using the variable auxID. The idea is read the map many times until all values of auxID become different of zero (while(auxID == 0). I don't know how use this value auxID to do a while(). All cases that I found use while reading from beginning to end but not many times.
Could you help me please?
Cheers!
struct STreeGenSimple /* Family structure declaration */
{
int ID;
int level;
int auxID;
int oldId;
int father;
int mother;
} ;
// ...
std::map<int, STreeGenSimple> IndivAuxIDSortedMap;
myfileReadAuxIdSorted.open("auxIdSorted.txt"); // REABRINDO ARQUIVO PARA LEITURA
while(myfileReadAuxIdSorted >> indivV)
{
STreeGenSimple& current_indivSortedAuxID = IndivAuxIDSortedMap[indivV];
current_indivSortedAuxID.ID = indivV; //assign AUX ID to the new record at ID indivV.
myfileReadAuxIdSorted >> auxIdV;
current_indivSortedAuxID.auxID = auxIdV;
myfileReadAuxIdSorted >> fatherV >> motherV >> levelV;
current_indivSortedAuxID.level = levelV;
current_indivSortedAuxID.father = fatherV;
current_indivSortedAuxID.mother = motherV;
};
std::map<int, STreeGenSimple>::const_iterator it4;
for (it4 = IndivAuxIDSortedMap.begin(); it4 != IndivAuxIDSortedMap.end(); ++it4)
{
cout << it4->first << '\t' << it4->second.ID << '\t' << it4->second.father << '\t' << it4->second.mother << '\t' << '\t' << it4->second.level << std::endl;
}
std::map<int, STreeGenSimple>::const_iterator iterSearch;
iterSearch = IndivAuxIDSortedMap.begin();
// * POSITION TO INCLUDE WHILE()
for (it4 = IndivAuxIDSortedMap.begin(); it4 != IndivAuxIDSortedMap.end(); ++it4)
{
iterSearch = IndivAuxIDSortedMap.find(it4->second.father);
if (iterSearch != IndivAuxIDSortedMap.end())
std::cout << "Value is: " << iterSearch->second.auxID << '\n';
else
std::cout << "Key is not in my_map" << '\n';
}
// END OF WHILE(). "FOR" WILL BE WITHIN "WHILE". I will update the auxID using FOR