📄 constream.h
字号:
//
// ConStream.h: interface for the ConStream class.
//
// Source code from:
//
// Serial Communications: A C++ Developer's Guide, 2nd
// Edition by Mark Nelson, IDG Books, 1999
//
// The ConStream class creates a C++ ostream object that can
// be used in Win32 C++ programs to write to a console window,
// often for debugging purposes. This utility code is included
// with as-is with no further documentation.
//
//
// This header file defines the entire interface to the ConStream class.
// ConStream is a class that works like a standard iostream, and writes
// to a console window when created in a Win32 application. You can only
// have a single console window open at a time, so only a single ConStream
// class is ordinarily created in an application.
//
#if !defined( _CONSTREAM_H )
#define _CONSTREAM_H
//
// Note that ConStream uses the standard C++ libraries that ship with
// Visual C++ 5.0 and later, not the older libraries with the .h suffix.
// The library would require some modifications to work with the older
// libraries.
//
#include <windows.h>
#include <iostream>
#include <fstream>
using namespace std;
//
// The ConStream class is derived from what we normally think of as ostream,
// which means you can use standard insertion operators to write to it. Of
// course, this includes insertion operators for user defined classes. At
// all times, a ConStream object is either writing out to to a FILE
// object attached to the NUL device, or a FILE object attached to a console
// created using the Win32 API. Which of the two is in use depends on whether
// or not the ConStream object has had its Open() or Close() method called.
//
class ConStream
: public basic_ostream<char>
{
public :
ConStream();
virtual ~ConStream();
void Open();
void Close();
bool IsOpen(){
return m_hConsole != INVALID_HANDLE_VALUE;
}
protected :
HANDLE m_hConsole;
basic_filebuf<char> *m_FileBuf;
basic_filebuf<char> m_Nul;
FILE *m_fNul;
FILE *m_fConsole;
};
#endif // !defined( _CONSTREAM_H )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -