Re:C++ has become a scripting language
by JanneVee on Wednesday October 16, 2013 @03:37PM
(#6561672)
How about
And to inform everyone. Cling as a C++ REPL exists. http://root.cern.ch/drupal/content/cling
[ Parent
| on HN ]
Re:C++ has become a scripting language
by pmelendez on Wednesday October 16, 2013 @03:48PM
(#6561743)
You are including way more lines of code... I don't get your point... sorry :(
Re:C++ has become a scripting language
by JanneVee on Wednesday October 16, 2013 @05:18PM
(#6562214)
I eliminated the loops and did the processing with STL algorithms and iterators. It is ugly as sin if you try to process lines like the original code. Most scripting languages do rather well with lines but C++ does not.
Re:C++ has become a scripting language
by abelsson on Wednesday October 16, 2013 @03:51PM
(#6561754)
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.
Re:C++ has become a scripting language
by JanneVee on Wednesday October 16, 2013 @05:16PM
(#6562206)
Yeah, it is not a scripting language for processing lines. Although the line nonsense has a benefit though it could be adapted to parse out records and by overloading the less than operator to sort on a specific column. But then you would might use AWK instead.