string的比较

bool operator==(const string &s1,const string &s2)const;//比较两个字符串是否相等
运算符”>”,”<",">=”,”<=","!="均被重载用于字符串的比较; int compare(const string &s) const;//比较当前字符串和s的大小 int compare(int pos, int n,const string &s)const;//比较当前字符串从pos开始的n个字符组成的字符串与s的大小

怎样声明一个C++字符串

声明一个字符串变量很简单:
string Str; //声明
这样我们就声明了一个字符串变量,但既然是一个类,就有构造函数和析构函数。上面的声明没有传入参数,所以就直接使用了string的默认的构造函数,这个函数所作的就是把Str初始化为一个空字符串。String类的构造函数和析构函数如下: