Skip to content

Instantly share code, notes, and snippets.

@FrancisGX
Created October 16, 2013 14:41
Show Gist options
  • Save FrancisGX/7008824 to your computer and use it in GitHub Desktop.
Save FrancisGX/7008824 to your computer and use it in GitHub Desktop.
This is a C++ program that sorts lines read from the first arg and writes them to the second arg.
#include<string>
#include<vector>
#include<algorithm>
#include<fstream>
using namespace std;
int main(int argc, char **argv) {
ifstream ifile(argv[1]);
ofstream ofile(argv[2]);
string line;
vector<string> data;
while(getline(ifile, line)) {
data.push_back(line);
}
sort(data.begin(), data.end());
for(const auto &i : data) {
ofile << i << std::endl;
}
return 0;
}
This is the same program written in Ruby
File.write(ARGV.pop, ARGF.each_line.sort.join)
@alassiter
Copy link

wow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment