國外做的比較好看的網(wǎng)站2022年度最火關(guān)鍵詞
C++ Primer(第5版) 練習 5.19
練習 5.19 編寫一段程序,使用do while循環(huán)重復(fù)地執(zhí)行下述任務(wù):首先提示用戶輸入兩個string對象,然后挑出較短的那個并輸出它。
環(huán)境:Linux Ubuntu(云服務(wù)器)
工具: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;
}