string类 成员函数简单示例(1)

来源:互联网 发布:阿里云国际绑定paypal 编辑:程序博客网 时间:2024/06/08 06:28
/* 比较2个string对象的大小,并输出。
 * */# include <iostream># include <string>using namespace std;int main(){string str1, str2;cout<<"input two strings:"<<endl;cin>>str1>>str2;if(str1>str2){cout<<"the big string is "<<str1<<endl;}elsecout<<"The big string is "<<str2<<endl;return 0;}
/*比较两个string对象的长度并输出*/# include <iostream># include <string>using namespace std;int main(){cout<<"input two strings:"<<endl;string str1, str2;cin>>str1>>str2;string::size_type len1, len2;len1 = str1.size();len2 = str2.size();if(len1 == len2)cout<<"\""<<str1<<"\""<<" and "<<"\""<<str2<<"\""<<" have the same length"<<endl;else if(len1>len2)cout<<"\""<<str1<<"\""<<" is longer than "<<"\""<<str2<<"\""<<endl;elsecout<<"\""<<str2<<"\""<<" and "<<"\""<<str1<<"\""<<" have the same length"<<endl;return 0;}
string::size_type
	
				
		
原创粉丝点击