做荣誉证书的网站,具有营销型网站有哪些,东莞清溪妇产科医院,网络规划师报名时间C Primer#xff08;第5版#xff09; 练习 3.39
练习 3.39 编写一段程序#xff0c;比较两个string对象。再编写一段程序#xff0c;比较两个C风格字符串的内容。
环境#xff1a;Linux Ubuntu#xff08;云服务器#xff09;
工具#xff1a;vim 代码块
/*******…C Primer第5版 练习 3.39
练习 3.39 编写一段程序比较两个string对象。再编写一段程序比较两个C风格字符串的内容。
环境Linux Ubuntu云服务器
工具vim 代码块
/************************************************************************* File Name: ex3.39.cpp Author: Mail: Created Time: Thu 01 Feb 2024 02:41:54 PM CST************************************************************************/#includeiostream
#includecstring
using namespace std;int main(){string s1, s2;coutEnter string1: ;getline(cin, s1);coutEnter string2: ;getline(cin, s2);if(s1 s2){coutstring1 is equal to string2.endl;}else if(s1 s2){coutstring1 is greater than string2.endl;}else{coutstring1 is less than string2.endl;}char s3[80];char s4[80];coutEnter s3: ;cin.getline(s3, sizeof(s3));fflush(stdin);coutEnter s4: ;cin.getline(s4, sizeof(s4));if(strcmp(s3, s4) 0){couts3 is equal to s4.endl;}else if(strcmp(s3, s4) 0){couts3 is greater than s4.endl;}else{couts3 is less than s4.endl;}return 0;
}运行结果显示如下