sを比較するための組み込み関数が必要stringです。私が持っているCスタイルの文字列の場合
strcmp();
しかし、stringクラスを処理するための関数が必要です。
string name1;
string name2;
に対して定義されている等価演算子operator==()を探していますstd::basic_string。
if (name1 == name2)
!=、<、<=、>など、他の比較演算子も使用できます>=。
と同じ機能を提供する which を使用できます。std::string::compare()strcmp()
std::string name1 = "John";
std::string name2 = "Micheal";
int result = name1.compare(name2);
おおよそ次のようになります。
const char* name1 = "John";
const char* name2 = "Micheal";
int result = std::strcmp(name1, name2);