c++中判断字符串相等
在C++中,可以使用==运算符来判断两个字符串是否相等。下面是一个示例代码:
#include <iostream>
#include <string>
int main() {
std::string str1 = "hello";
std::string str2 = "world";
if (str1 == str2) {
std::cout << "str1 and str2 are equal." << std::endl;
} else {
std::cout << "str1 and str2 are not equal." << std::endl;
}
return 0;
}
在上面的示例中,我们使用==运算符比较了两个字符串str1和str2的内容是否相等。如果相等,则输出"str1 and str2 are equal.",否则输出"str1 and str2 are not equal."。
原文地址: https://www.cveoy.top/t/topic/h97t 著作权归作者所有。请勿转载和采集!