プログラムに辞書を実装するためにC++マップを使用しています。structure.name
私の関数は引数として構造体を取得し、メンバーに基づいて関連付けられた値を返す必要がありchar named[32]
ます。次のコードは私の問題を示しています。
map <const char *, const char *> myMap;
myMap.insert(pair<const char *, const char *>("test", "myTest"));
char *p = "test";
char buf[5] = {'\0'};
strcpy(buf, "test");
cout << myMap.find(p)->second << endl; // WORKS
cout << myMap.find("test")->second << endl; // WORKS
cout << myMap.find(buf)->second << endl; // DOES NOT WORK
3番目のケースが機能しない理由と、それを機能させるにはどうすればよいかわかりません。上記のコードをデバッグして、渡された値を監視しましたが、それでも問題を理解できません。
ありがとう!