在C++中,可以使用strcmp函数来比较两个看起来相同的CStrings。strcmp函数用于比较两个字符串是否相等,并返回一个整数值。
下面是一个示例:
#include
#include
int main() {
const char* str1 = "Hello";
const char* str2 = "Hello";
int result = strcmp(str1, str2);
if (result == 0) {
std::cout << "The strings are equal" << std::endl;
} else {
std::cout << "The strings are not equal" << std::endl;
}
return 0;
}
在上面的示例中,我们定义了两个相同的CStrings:str1和str2。然后,我们使用strcmp函数比较这两个字符串,并将返回值存储在result变量中。
如果result的值为0,表示两个字符串相等;如果result的值不为0,则表示两个字符串不相等。
在上面的示例中,由于str1和str2的值相同,所以输出结果为"The strings are equal"。