C++笔记:习题 3.7 (3.2.4)

/* C++ Primer 3.2.4 習題 3.7
 * 題目: 編寫程序實現從標準輸入讀入兩個 string 對象,比較其是否相等,哪個較大,哪個較長。
 */

#include #include 

using std::cin;
using std::cout;
using std::string;
using std::endl;

int main()
{
	string s1, s2;
	getline(cin, s1);
	getline(cin, s2);
	if (s1 == s2)
		cout << "S1, S2 is the same." << endl;
	else if (s1 > s2)
		cout << "S1 is biger than S2." << endl;
	else
		cout << "S2 is biger than S1." << endl;
	if (s1.length() == s2.length())
		cout << "S1, S2 is the same length." << endl;
	else if (s1.length() > s2.length())
		cout << "S1 is longer than S2." << endl;
	else
		cout << "S2 is longer than S1." << endl;
	return 0;
}

题外话:我帮你整理了包括 AI 写作、绘画、视频(自媒体制作)零门槛 AI 课程 + 国内可直接顺畅使用的软件。想让自己快速用上 AI 工具来降本增效,辅助工作和生活?限时报名

当前页阅读量为: