c++ - The key exist in the map variable but find cannot find it -


i have created class named myclass , define map as:

    map<string,myclass> myclasssample; 

i inserted variable , key:

     myclasssample["id"].setstring1_1("hi"); 

note: setstring1_1 setter of class

then use code see if key available:

    if (myclasssample.find("id") != myclasssample.end())     {     printf("problem");     } 

problem shown out put. condition true! function can return string!

return myclasssample["id"].getstring1(); 

note: getstring1 getter of class

you seem have misunderstanding of how map::find works. returns end() iterator when key you're searching cannot found. condition check if key present needs be

if (myclasssample.find("id") == myclasssample.end()) //                           ^^   ==, not != {   printf("problem"); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -