参数的书写要完整,不要贪图省事只写参数的类型而省略参数名字

参数的书写要完整,不要贪图省事只写参数的类型而省略参数名字。

 1 #include <iostream>
 2 #include <string>
 3 
 4 using namespace std;
 5 
 6 //测试字符串(string)对象
 7 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 8 
 9 int main(int argc, char** argv) {
10       //创建string对象
11     string s1,s2;
12 
13     //string对象的赋值运算
14     s1="One";
15     s2="Two";
16     cout<<"s1="<<s1<<endl;
17     cout<<"s2="<<s2<<endl;
18 
19     //string对象的连接运算
20     string s3;
21     s3=s1+" and "+s2;
22     cout<<"s3="<<s3<<endl;
23 
24     //组合赋值连接运算
25     s3+=" and Three";
26     cout<<"s3="<<s3<<endl;
27 
28     //比较运算及其结果显示
29     for (int i=1;i<=3;i++) {
30         cout<<"---------------------"<<endl;
31         cout<<"s1=";
32         cin>>s1;
33         cout<<"s2=";
34         cin>>s2;
35         if (s1<s2)   //小于
36             cout<<s1<<" < "<<s2<<endl;
37         if (s1<=s2)  //小于等于
38         cout<<s1<<" <= "<<s2<<endl;
39         if (s1==s2)  //等于
40         cout<<s1<<" == "<<s2<<endl;
41         if (s1>s2)   //大于
42         cout<<s1<<" > "<<s2<<endl;
43         if (s1>=s2)  //大于等于
44         cout<<s1<<" >= "<<s2<<endl;
45         if (s1!=s2)  //不等
46             cout<<s1<<" != "<<s2<<endl;
47     }
48     return 0;
49 }
原文地址:https://www.cnblogs.com/borter/p/9413545.html