Exercice_3.7_判断两个字符串的大小和长度

//判断两个字符串的大小和长度
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s1,s2,msg;
    string::size_type len1,len2;
    cout<<"Input s1 and s2."<<endl;
    cin>>s1>>s2;


    if(s1==s2)
        msg="They are equal.";
    len1=s1.size();
    len2=s2.size();

    if(len1!=len2)
        msg=len1>len2?"s1 is longer.":"s2 is longer.";
    else
        msg="They have same length.";
    cout<<msg<<endl;
    return 0;
}

原文地址:https://www.cnblogs.com/mrbourne/p/9959478.html