[ Back to the overview Matrix ]

Test case : Sort 2 using C++

Lines used: 13
#include <iostream>
#include <string>
#include <vector>
#include <fstream>

int main(int argc, char **argv) {
  std::ifstream in(argv[1]);
  std::ofstream out("sorted.txt");
  std::vector<std::string> lines;
  for (std::string buf; getline(in, buf);)
    lines.push_back(buf);
  std::sort(lines.begin(), lines.end());
  for (unsigned i(0); i < lines.size(); ++i)
    out << lines[i] << '\n';
}
Contributed by Jeremy Yallop , jeremy at yallop.org