Stream Functions

Introduction

The <utilities/stream.h> header supplies some utility functions that work on streams.

Reading from a Stream

std::string
utilities::read_line(std::istream &s,
1                     std::string_view comment_begin = "#");
std::size_t
utilities::read_line(std::istream &s, std::string &line,
2                     std::string_view comment_begin = "#");
1
This function reads a ‘line’ from a stream and returns that as a std::string.
2
Overwrites the ‘line’ argument with the contents from a stream s. Returns the number of characters placed into line.

These functions differ from std::getline in a few ways:

  1. They ignore blank lines in the input stream.
  2. They allow for long lines by assuming that lines that end with a “\” continue to the next.
  3. They strip out comment lines and trailing comments.

Comment lines begin with “#” by default.

Back to top