I'm trying to brush up on a few of the key STL concepts. I wrote the below program to understand working of std::pair
and maps
, but I'm getting a nasty compile error. Tried adding all the headers as well but, unable to figure out whats wrong so far. Please help.
void testMaps()
{
DB_Type phoneDb;
PhoneInfoList_Type v1(8);
PhoneInfo_Type(*phoneInfoGenerator)() = phoneInfoGen;
DBIT_Type it;
PhoneInfoList_Type::iterator phit;
int i = 0, j = 0;
for (phit = v1.begin(); phit != v1.end(); ++phit)
{
v1.push_back(phoneInfoGen());
}
for (phit = v1.begin(); phit != v1.end(); ++phit)
{
phoneDb.insert(*phit);
}
int choice;
std::cout << "Enter choice 0. Search by name, 1. Search by no., 2. Exit\n";
while (1)
{
switch (choice)
{
case 0:
{
std::cout << "Enter name:";
std::string name;
std::cin >> name;
DBIT_Type it = std::find(phoneDb.begin(), phoneDb.end(), name);
if (it != phoneDb.end())
{
std::cout <<"\n Phone no of " << name << "is " << it->second << "\n";
}
else
{
std::cout << "Name not found\n";
}
}break;
case 1:
{
std::cout << "Enter phone no:";
int ph;
std::cin >> ph;
DBIT_Type it = std::find(phoneDb.begin(), phoneDb.end(), ph);
if (it != phoneDb.end())
{
std::cout << "\n Name of person with phone no " << ph << "is " << it->first << "\n";
}
else
{
std::cout << "Name not found\n";
}
}
break;
default:
break;
}
}
}
The compile error that I'm getting :
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(3026): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::pair<const _Kty,_Ty>' (or there is no acceptable conversion)
1> with
1> [
1> _Kty=std::string
1> , _Ty=int
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\system_error(410): could be 'bool std::operator ==(const std::error_condition &,const std::error_code &) throw()'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\system_error(402): or 'bool std::operator ==(const std::error_code &,const std::error_condition &) throw()'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\exception(507): or 'bool std::operator ==(const std::exception_ptr &,std::nullptr_t)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\exception(502): or 'bool std::operator ==(std::nullptr_t,const std::exception_ptr &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\exception(497): or 'bool std::operator ==(const std::exception_ptr &,const std::exception_ptr &)'
1> while trying to match the argument list '(std::pair<const _Kty,_Ty>, const std::string)'
1> with
1> [
1> _Kty=std::string
1> , _Ty=int
1> ]