當前位置:成語大全網 - 新華字典 - C++ 輸入5個字符串,按英文字典順序,由小到大順序輸出

C++ 輸入5個字符串,按英文字典順序,由小到大順序輸出

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <iterator>

using namespace std;

int main()

{

vector<string> vs;

string s;

for (int i = 0; i < 5; i++) cin >> s, vs.push_back(s);

sort(vs.begin(), vs.end());

copy(vs.begin(), vs.end(), ostream_iterator<string>(cout, "\n"));

return 0;

}