//为了方便,要包含的文件会不同,但我没有删
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <cstring> //和C语言的string.h其实是一个版本
using std::bitset;
using std::vector;
using std::cin;
using std::endl;
using std::cout;
using std::string;
//---------------------------------------------------------------------------
int main()
{
//string大小的比较--------------------------------------------------------
string s1="hello, I am String",s2="hello, I am String's daughter";
if(s1<s2)
cout<<s1<<"小于"<<s2<<endl;
else
{
if(s1>s2)
cout<<s1<<"大于"<<s2<<endl;
else
cout<<s1<<"="<<s2<<endl;
}
//----------------------------------------------------------------
//c风格字符串大小比较
const char *ca="hello, I am CStyle",*ca1="hello, I am another CStyle.";
if(strcmp(ca,ca1)>0)
{
for(;*ca!='/0';++ca) //先想用*ca!=null,但说null没有这个变量,应该是要引用什么库才行的,但忘了,只能改用标准的/0了
cout<<*ca;
cout<<"大于";
for(;*ca1!='/0';++ca1)
cout<<*ca1;
cout<<endl;
}
else if(strcmp(ca,ca1)<0)
{
for(;*ca!='/0';++ca)
cout<<*ca;
cout<<"小于";
for(;*ca1!='/0';++ca1)
cout<<*ca1;
cout<<endl;
}
else if(strcmp(ca,ca1)==0)
{
for(;*ca!='/0';++ca)
cout<<*ca;
cout<<"等于";
for(;*ca1!='/0';++ca1)
cout<<*ca1;
cout<<endl;
}
//-------------------------------------------------------------
return 0;
}
/*
117页习题4.25,比较两个string和两个C风格字符串
*/