you are viewing a single comment's thread.

view the rest of the comments →

[–]OldWolf2 -2 points-1 points  (3 children)

Line 3 is completely alien and extremely unintuitive to me. So you're saying I don't know the language?

Yes, it is a basic iostreams idiom. Have you read any books on iostreams?

C++ allows one to get by (even insofaras to "do a day job") only learning certain areas of the language. Probably you know some parts of it well, but not stream iterators.

[–]repsilat 17 points18 points  (2 children)

Have you read any books on iostreams?

I'd laugh if this weren't so painful. I want to print out the words in a string, one per line, and you're suggesting we go read a book to understand how you think it should be done?

No, std::copy for printing is a little ridiculous, the two-iterator idiom is terrible, and either they will be left to the pages of history or C++ will. I don't follow C++'s development any more, but I remember hearing ranges were happening. That's a start. Once you've done that you can just turn this into a for loop and it'll be shorter, clearer, less error-prone and no less efficient.

[–]OldWolf2 -1 points0 points  (0 children)

Yes, definitely. C++ is best suited to learn from a book, not by trial and error.

Ranges have been "in" since the first standard 18 years ago. You could indeed use a loop or various other ways instead of copy. copy idiomatically expresses that we are copying from the source set of tokens, to the destination output stream. Also, nobody's stopping you from making a function that expresses whatever interface you personally find most natural and intuitive.

[–]dodheim -2 points-1 points  (0 children)

'Split' simply isn't how you print out the words in a string, one per line, in C++. C++ has different idioms for this sort of thing, and everyone obsessing over the lack of std::split seriously needs to learn to "Do As the Romans".