假定一行就是一個字串按第一個字母從小到大排序,第一個字母相同則看第二個#include <iostream>#include <fstream>#include <string>#include <vector>#include <algorithm>using namespace std;int main(){string s;vector<string> a;fstream fin("1.txt", ios::in),fout("3.txt", ios::out);if(!fin){cerr << "cannot open!" << endl;return -1;}while(!fin.eof()){getline(fin,s,"\n");a.push_back(s);}sort(a.begin(),a.end());for(vector<string>::iterator t = a.begin(); t != a.end(); t++)fout << *t << endl;fin.close();fout.close();return 0;}
假定一行就是一個字串按第一個字母從小到大排序,第一個字母相同則看第二個#include <iostream>#include <fstream>#include <string>#include <vector>#include <algorithm>using namespace std;int main(){string s;vector<string> a;fstream fin("1.txt", ios::in),fout("3.txt", ios::out);if(!fin){cerr << "cannot open!" << endl;return -1;}while(!fin.eof()){getline(fin,s,"\n");a.push_back(s);}sort(a.begin(),a.end());for(vector<string>::iterator t = a.begin(); t != a.end(); t++)fout << *t << endl;fin.close();fout.close();return 0;}