标签:str1 对比 end str code 描述 compare include mic
功能描述:
比较方式:
= 返回 0
> 返回 1
< 返回 -1
函数原型:
int compare(const string &s) const;
//与字符串s比较
int compare(const char *s) const;
//与字符串s比较
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 void test_01() 6 { 7 string str1 = "hello!"; 8 string str2 = "hillo!"; 9 10 if (str1.compare(str2) == 0) 11 { 12 cout << "str1和str2相同!" << endl; 13 } 14 else 15 { 16 cout << "str1和str2不相同!" << endl; 17 } 18 } 19 20 int main(void) 21 { 22 test_01(); 23 24 system("pause"); 25 return 0; 26 27 }
标签:str1 对比 end str code 描述 compare include mic
原文地址:https://www.cnblogs.com/huanian/p/13272807.html