Linux 拨号vps windows公众号手机端

c++字符串比较是否相等的方法是什么

lewis 7年前 (2018-03-28) 阅读数 6 #程序编程
文章标签 c++

在C++中,可以使用==运算符来比较两个字符串是否相等。例如:

#include <iostream>
#include <string>

int main() {
    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;
    }

    return 0;
}

上面的代码中,使用==运算符来比较str1str2是否相等,如果相等则输出"The strings are equal.“,否则输出"The strings are not equal.”。

版权声明

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

发表评论:

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

热门