3.7
题目描述:编写一个程序读入两个string对象,测试它们是否相等。若不相等,则指出两个中哪个较大。接着,改写程序测试它们的长度是否相等,若不相等指出哪个较长。
源码解答:
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
/*test the two strings*/
string s1, s2;
cout << "please input two strings:" << endl;
cin >> s1 >> s2;
if (s1 == s2)
{
cout << "the two strings is equl" << endl;
}
else if (s1>s2)
{
cout << "the first string is bigger" << endl;
}
else
{
cout << "the second string is bigger" << endl;
}
cout << "please input two strings:" << endl;
cin >> s1 >> s2;
if (s1.size() =&