sort()根据字母排列字典顺序
string s1[3]={"alower","flow","flws"};
string s2[3]={"flower","flow","flowe"};
vector<string> str1(s1,s1+3),str2(s2,s2+3);
sort(str1.begin(),str1.end());
sort(str2.begin(),str2.end());
for ( vector<string>::iterator it = str1.begin(); it != str1.end(); ++it )
cout << *it<< ' ';
cout<<endl;
for ( vector<string>::iterator it = str2.begin(); it != str2.end(); ++it )
cout << *it<< ' ';
结果:
alower flow flws
flow flowe flower