将6个字符串存入vector容器中,并采用一种STL算法排序并输出
#include <iostream>
#include <iterator>
#include <vector>
#include <ostream>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;
void main(){
vector<string> coll{"asayjk", "bhjresaf", "cebnmr", "dttzlo", "cqwsw", "actrfs" };
/*coll.push_back("asayjk");
coll.push_back("bhjresaf");
coll.push_back("cebnmr");
coll.push_back("dttzlo");
coll.push_back("cqwsw");
coll.push_back("actrfs");*/
copy(coll.begin(), coll.end(), ostream_iterator<string>(cout, " "));
sort(coll.begin(), coll.end(), greater<string> ());// 默认是从小到大排序
cout << endl;
copy(coll.begin(), coll.end(), ostream_iterator<string>(cout, " "));
cin.get();
}