mardi 31 mars 2015

Incorrect output while comparing two strings C++

I have class CPerson that in simple looks like this:



CPerson
{
public:
CPerson();
pair<string, string> CP_surname_name;
vector<CCar> CP_CarList;
};


then I have a vector<CPerson> CR_people It's sorted vector by pair CP_surname_name. The problem is, when I need to compare surname and name, inputted by user firstly I go throug vector, if there is already the person I am looking for.



auto it = lower_bound(CR_people.begin(), CR_people.end(), surname_name);


I have overriden operator< so sorting is fine. But when I need to check, if the surname_name is exact the same as CP_surname_name by:



if(surname_name == (*it).CP_surname_name){...}


it gives me falseeven they are same. I already tried:



if(surname_name.first == (*it).CP_surname_name.first && surname_name.second == (*it).CP_surname_name.second){...}


and it works the same. I also tried strcmp() but it gives me errors, because I am using string, not char* so I tried append .c_str() to retype it, and that gave me also wrong results. The compare() in String class did not work as well. Thanks for any help, and sorry for my bad english.


Aucun commentaire:

Enregistrer un commentaire