The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

ambs (22) [Avatar] Offline
#1
Page 6, end of second paragraph

The only task of the count_lines function is to convert its input (the file name) to the type that the std::count can understand (a pair of stream iterators).


My C++ is limited, but I think the first argument to std::count is the iterator, and the second the type of the iterator elements.
Ivan Cukic (104) [Avatar] Offline
#2
I don't understand what you meant.

The signature of count is:

count( InputIt first, InputIt last, const T &value );


The first two arguments are iterators, and the last one is the value we are counting.
ambs (22) [Avatar] Offline
#3
I think it was that problem with the markup in the code that confused me.

This is the exact code:
return std::count(
        std::istream_iterator<char>(in),
        std::istream_iterator<char>(),
        '\n');


So, yes, two iterators and the char to count. Sorry.