streambuf


1. Reading a File into a Stream

#include <fstream>
#include <streambuf>

int main() {
  std::ifstream file("file.txt");
  if (!file) {
    std::cerr << "Error opening file" << std::endl;
    return 1;
  }

  std::streambuf* buf = file.rdbuf();
  std::string contents(buf->in_avail());
  file.read(&contents[0], contents.size());

  std::cout << contents << std::endl;

  return 0;
}

2. Writing to a File from a Stream

3. Copying Data from One Stream to Another

4. Creating a Custom Stream Buffer

5. Using streambuf with std::getline

6. Using streambuf to Read from a Pipe

7. Using streambuf with a Memory-Mapped File

8. Using streambuf to Read from a Network Socket

9. Using streambuf to Write to a Network Socket

10. Using streambuf to Create a Custom Filter

11. Using streambuf to Convert Line Endings