c++中string怎么比较字符串内容

c++
978
2024/2/18 14:14:42
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在C++中,可以使用==运算符来比较两个字符串的内容。例如:

std::string str1 = "hello";
std::string str2 = "world";

if (str1 == str2) {
    std::cout << "The strings are equal" << std::endl;
} else {
    std::cout << "The strings are not equal" << std::endl;
}

如果要比较两个字符串的内容是否相等,可以使用==运算符;如果要比较两个字符串的内容是否不相等,可以使用!=运算符。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: C++的Lambda表达式有哪些用途