#include<iostream>
using namespace std;
int main()
{
string s1("moophy"), s2("pezy");
if (s1 == s2)//如果s1和s2所含的字符完全一样,则他们相等
cout << "same" << endl;
else if (s1 > s2)
cout << "moophy>pezy" << endl;
else
cout << "moophy<pezy" << endl;
cout << "===============" << endl;
const char* cs1 = "wangyue";
const char* cs2 = "pezy";
//c风格字符串不是一种类型,而是为了表达和使用字符串而形成的一种约定俗成的写法,存放在字符数组中以‘\0’结束
//使用数组的时候真正使用的是指向数组元素的指针
auto result = strcmp(cs1, cs2);
if (result == 0)
cout << "same string" << endl;
else if (result < 0)
cout << "w<p" << endl;
else
cout << "w>p" << endl;
return 0;
}
3.39
最新推荐文章于 2024-07-20 02:49:56 发布