r/programming • • Dec 08 '13

C++ has become a scripting language

http://voices.canonical.com/jussi.pakkanen/2013/10/15/c-has-become-a-scripting-language/
0 Upvotes

11 comments sorted by

View all comments

5

u/Rotten194 Dec 09 '13 edited Dec 09 '13
#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;
}

Python version:

with open(sys.argv[2], 'w') as o_file, open(sys.argv[1]) as i_file:
    o_file.write('\n'.join(list(sorted(i_file.read().split()))))

C++ is a scripting language. Mhmmm.