|
|
|
|
|
by abelsson
4625 days ago
|
|
Hah, I was just about to post more or less exactly the same code. :) It's funny, had the author tweaked the problem just slightly to try make C++ look good by saying that the program should output sorted words instead of lines, you could have deleted the entire Line nonsense. Had the problem been to output sorted, unique words, you could have made the rather elegant: int main(int argc, const char* argv[])
{
using input = istream_iterator<string>;
using output = ostream_iterator<string>;
ifstream inputfile(argv[1]);
ofstream outputfile(argv[2]);
set<string> words{input(inputfile), input()};
copy(words.begin(), words.end(), output(outputfile, "\n"));
}
But then again, it's not exactly in C++'s favor as a scripting language that copying words is easy, while lines is hard. |
|