Another way to do it in C++ is:
#include <iterator>
#include<vector>
#include<algorithm>
#include<fstream>
using namespace std; // Bad but shorter!
int main(int argc, char** argv) {
ifstream infile(argv[1]);
ofstream outfile(argv[2]);
ifstream_iterator<string> start(infile), end;
vector<string> lines(start, end);
sort(lines.begin(), lines.end());
copy(lines.begin(), lines.end(), ostream_iterator<char>(outfile, "\n"));
}