使用vector向量类模板对输入字符串进行排序--基础内容
更新:2015-10-02
浏览:1+次
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<algorithm>
#define charSize 128
using namespace std;
void Output(char ch)
{
cout << ch << " ";
}
void main()
{
char String[charSize];
vector<char>charVector;
cout << "please input:" << endl;
cin >> String;
for (int i = 0; String[i] != '\0'; i++) { charVector.push_back(String[i]); }
cout << "输出未排序前字符串:";
for_each(charVector.begin(), charVector.end(), Output);
cout << endl << "输出排序后字符串:";
sort(charVector.begin(), charVector.end()); //排序
for_each(charVector.begin(), charVector.end(), Output);
cout << endl;
}