C++字符串的比较

==!=<=>=<>操作符都可以用于进行 string 类型字符串的比较,这些操作符两边都可以是 string 字符串,也可以一边是 string 字符串另一边是字符串数组。

举个例子:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s1 = "secondsecondthird";
    string s2 = "secondthird";
    if( s1 == s2 )
        cout<< " == " <<endl;
    if( s1 != s2 )
        cout<< " != " <<endl;
    if( s1 < s2 )
        cout<< " < " <<endl;
    if( s1 > s2 )
        cout<< " > " <<endl;
    return 0;
}
程序最终运行结果:

!=
<