M
Mike Copeland
I continue to have problems working with STL containers of
structures, and nothing in Google searches addresses the kind of things
I'm doing. 8<{{
My (latest) problem is that although I can populate a list, I can't
see how to access a specific object and update it. The application here
is one which I'm counting the occurrences of Cities & States in a data
file - I chose a list to do this work because I need to sort the list
after it's build and report by State.
struct ENTLOCS
{
string sortKey;
string ctsKey;
string stateName;
string cityName;
int eCount;
bool operator <(const ENTLOCS &rhs) const // comparison operator
{
return stateName < rhs.stateName;
}
} eWork;
[...]
char s80[80];
list<ENTLOCS> hStats;
list<ENTLOCS>::iterator eIter;
[...]
while(fv1.readln(s80, true)) // note: my own I/o routine...
{
bool bFound = false;
eWork.ctsKey = sCTS, eWork.cityName = CTSCity;
eWork.stateName = CTSState;
eWork.sortKey = CTSState, eWork.sortKey +=CTSCity;
for(eIter = hStats.begin(); eIter != hStats.end(); eIter++)
{
ENTLOCS eTemp = *eIter;
if(eTemp.ctsKey == sCTS)
{
bFound = true; break;
}
} // for
if(bFound == false)
{
eWork.eCount = 1;
hStats.push_back(eWork);
}
else
{
ENTLOCS eTemp = *eIter;
eTemp.eCount++; // this doesn't work... 8<{{
}
} // while
What am I missing here? TIA
structures, and nothing in Google searches addresses the kind of things
I'm doing. 8<{{
My (latest) problem is that although I can populate a list, I can't
see how to access a specific object and update it. The application here
is one which I'm counting the occurrences of Cities & States in a data
file - I chose a list to do this work because I need to sort the list
after it's build and report by State.
struct ENTLOCS
{
string sortKey;
string ctsKey;
string stateName;
string cityName;
int eCount;
bool operator <(const ENTLOCS &rhs) const // comparison operator
{
return stateName < rhs.stateName;
}
} eWork;
[...]
char s80[80];
list<ENTLOCS> hStats;
list<ENTLOCS>::iterator eIter;
[...]
while(fv1.readln(s80, true)) // note: my own I/o routine...
{
bool bFound = false;
eWork.ctsKey = sCTS, eWork.cityName = CTSCity;
eWork.stateName = CTSState;
eWork.sortKey = CTSState, eWork.sortKey +=CTSCity;
for(eIter = hStats.begin(); eIter != hStats.end(); eIter++)
{
ENTLOCS eTemp = *eIter;
if(eTemp.ctsKey == sCTS)
{
bFound = true; break;
}
} // for
if(bFound == false)
{
eWork.eCount = 1;
hStats.push_back(eWork);
}
else
{
ENTLOCS eTemp = *eIter;
eTemp.eCount++; // this doesn't work... 8<{{
}
} // while
What am I missing here? TIA