Linux 拨号vps windows公众号手机端

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

lewis 9年前 (2016-12-11) 阅读数 7 #程序编程
文章标签 c++

在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;
}

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

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门