C++ Primer(第5版) 练习 5.19
练习 5.19 编写一段程序,使用do while循环重复地执行下述任务:首先提示用户输入两个string对象,然后挑出较短的那个并输出它。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块
/*************************************************************************
> File Name: ex5.19.cpp
> Author:
> Mail:
> Created Time: Mon 12 Feb 2024 04:09:04 PM CST
************************************************************************/
#include<iostream>
#include<string>
using namespace std;
int main(){
string str1, str2;
do{
cout<<"Enter string1: ";
cin>>str1;
cout<<"Enter string2: ";
cin>>str2;
string shortStr = str1.size() > str2.size() ? str2 : str1;
cout<<"The shorter string is "<<shortStr<<endl;
} while(cin);
return 0;
}