Skip to main content
2 of 3
added 264 characters in body
Chris
  • 10.3k
  • 1
  • 9
  • 66

Error reporting

To properly replicate the functionality of wc the error in this loop should print to std::cerr rather than std::cout.

    /* Loop over all the specified files */
    for (auto fileName: files) {
        std::ifstream   file(fileName);
        if (!file) {
            std::cout << "Unknown file: " << fileName << "\n";
        }
        else {
            display(file, fileName, options);
        }
    }

As I can see on my test machine:

% wc foo
wc: foo: open: No such file or directory
% wc foo 2> /dev/null 
% 

Fortunately, it's about the simples fix imaginable. All of three characters.

Strings

Consider std::string_view vs. const std::string&.

From Stack Overflow: How exactly is std::string_view faster than const std::string&?

Chris
  • 10.3k
  • 1
  • 9
  • 66