⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 use_sbuf.cpp

📁 不错书对C++/C程序员很有用的大家不要错过.
💻 CPP
字号:
// Operations with streambufs.
#include <iostream.h>
#include <fstream.h>

void main(void)
 {
   int c;
   const char *filename = "_junk_.$$$";
   ofstream outfile;
   streambuf *out, *input = cin.rdbuf();

   // Position at the end of file. Append all text.
   outfile.open( filename, ios::ate | ios::app);
   if (!outfile) 
    {
      cerr << "Could not open " << filename;
      return(-1);
    }

   out = outfile.rdbuf();  // Connect ofstream and streambuf.

   clog << "Input some text. Use Control-Z to end." << endl;
   while ( (c = input -> sbumpc() ) != EOF)
    {
      cout << char(c);                         // Echo to screen.
      if (out -> sputc(c) == EOF)
         cerr << "Output error";
      }
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -