编一个程序读入两个string对象,测试他们是否相等。若不等,则指出两个中那个较大。接着,改写程序测试他们的长度是否相等,若不等指出那个较长。
#include<string>
#include<iostream>using namespace std;
int main()
{
string line1, line2;
cout << "Enter two strings :" << endl;
getline(cin,line1);
getline(cin,line2);
if(line1 == line2 )
cout << "The two lines is same!" << endl;
else {
string big;
big = line1 > line2 ? line1 : line2;
cout << "The \" " << big << " \" is bigger!" <<endl;
if(line1.size() == line2.size())
cout << "The long of the two strings is equal !" << endl;
else {
string len;
len = line1.size() > line2.size() ? line1 : line2;
cout << "The \" " << len << " \" is longger! " << endl;
}
return 0;
}