C++string容器-字符串比较
string字符串比较功能描述:字符串之间的比较比较方式:通常用来比较两个字符串是否相等函数原型:代码如下:#include <iostream>using namespace std;#include <cstring>//string字符串比较void test01() {string str1 = "hello";string str2 = "hello";strin
·
string字符串比较
功能描述:
字符串之间的比较
比较方式:
通常用来比较两个字符串是否相等
函数原型:
代码如下:
#include <iostream>
using namespace std;
#include <cstring>
//string字符串比较
void test01() {
string str1 = "hello";
string str2 = "hello";
string str3 = "xello";
if (str1.compare(str2) == 0) {
cout << "str1 等于 str2" << endl;
}
if (str3.compare(str1) > 0) {
cout << "str3 大于 str1" << endl;
}
}
int main() {
test01();
return 0;
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)