R
repairman2003
I'm trying to keep track of two objects, a vector of strings and a user
defined date, ints set up in a struct. Having some trouble with it
keeping track of the information though.
//Defined as private data memebers of a class
vector<string> serviceRecord;
map<Date,vector<string> > serviceMap;
//In a constructor of a class
serviceMap.insert(make_pair(date1,serviceRecord));
//Function that adds a new service to the map
void addService(Date newDate,string newService)
{
serviceRecord.push_back(newService);
serviceMap.insert(make_pair(newDate,serviceRecord));
}
//In the main program that should output all of the service records for
each date
Date tempDate;
vector<string>::iterator sIter=services.begin();
std::map<Date,vector<string> >::iterator mIter;
std::map<Date,vector<string> >::iterator mIter2;
mIter=map.begin();
while(mIter!=map.end())
{
mIter2=map.find(mIter->first);
sIter=mIter->second.begin();
cout<<"\nOn "<<mIter->first.day<<"/"<<mIter->first.month<<"/"
<<mIter->first.year<<": ";
while(sIter!=mIter2->second.end())
{
cout<<"\n"<<*sIter;
sIter++;
}
mIter++;
}
First a record is created using the constructor, should have this as
the values:
date.day=26
date.month=10
date.year=2005
service="Client recieved a new service"
Then the record is updated using the addService function and should
then have these values:
date.day=26
date.month=10
date.year=2005
service="Client recieved a new service"
date.day=27
date.month=10
date.year=2005
service="Client recieved a new service today"
When the records are outputed with that while loop, it outputs this
instead:
On 10/26/2005:
Client recieved a new service
On 10/27/2005:
Client recieved a new service
Client recieved a new service today
It should only output the second statement, not both.
What should I change in my program to make it work correctly?
Thanks
defined date, ints set up in a struct. Having some trouble with it
keeping track of the information though.
//Defined as private data memebers of a class
vector<string> serviceRecord;
map<Date,vector<string> > serviceMap;
//In a constructor of a class
serviceMap.insert(make_pair(date1,serviceRecord));
//Function that adds a new service to the map
void addService(Date newDate,string newService)
{
serviceRecord.push_back(newService);
serviceMap.insert(make_pair(newDate,serviceRecord));
}
//In the main program that should output all of the service records for
each date
Date tempDate;
vector<string>::iterator sIter=services.begin();
std::map<Date,vector<string> >::iterator mIter;
std::map<Date,vector<string> >::iterator mIter2;
mIter=map.begin();
while(mIter!=map.end())
{
mIter2=map.find(mIter->first);
sIter=mIter->second.begin();
cout<<"\nOn "<<mIter->first.day<<"/"<<mIter->first.month<<"/"
<<mIter->first.year<<": ";
while(sIter!=mIter2->second.end())
{
cout<<"\n"<<*sIter;
sIter++;
}
mIter++;
}
First a record is created using the constructor, should have this as
the values:
date.day=26
date.month=10
date.year=2005
service="Client recieved a new service"
Then the record is updated using the addService function and should
then have these values:
date.day=26
date.month=10
date.year=2005
service="Client recieved a new service"
date.day=27
date.month=10
date.year=2005
service="Client recieved a new service today"
When the records are outputed with that while loop, it outputs this
instead:
On 10/26/2005:
Client recieved a new service
On 10/27/2005:
Client recieved a new service
Client recieved a new service today
It should only output the second statement, not both.
What should I change in my program to make it work correctly?
Thanks