首页 > C++入门教程 > C++ String类型
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; }程序最终运行结果:
!=
<
声明:《C++系列教程》为本站“54笨鸟”官方原创,由国家机构和地方版权局所签发的权威证书所保护。