The <utilities/stream.h> header provides utility functions for streams.
The functions differ from std::getline in a few ways:
- They ignore blank lines in the input stream.
- They allow for long lines by assuming that lines that end with a "\" continue to the next.
- They strip out comment lines and trailing comments where comment lines begin with "#" by default.
std::string utilities::read_line(std::istream &s, std::string_view comment_begin = "#");reads a "line" from a stream and returns that as a string.
std::size_t utilities::read_line(std::istream &s, std::string &line, std::string_view comment_begin = "#");overwrites the 'line' argument with the contents of a stream and returns the number of characters read into 'line’.
We supply a method that rewinds an input stream to the start.
std::istream & rewind(std::istream &is);and another that returns the number of non-comment lines in the stream.
std::size_t line_count(std::istream &is, std::string_view comment_begin = "#");If the comment_begin argument is empty, line_count uses std::getline to read the lines.
Otherwise, we use our read_line(...) function, so comment lines are excluded, etc.
Warning
These two functions only work with file streams, etc.