Win32 C++从类返回 cout 功能
Win32 C++ Return cout Functionality From a Class
>我正在处理一个简单的类,因此如果我使用 cout "equivalent",它将显示控制台,如果我不这样做,控制台不会弹出。
最终结果,如果可能的话,尝试使用一些简单的东西,例如:O.C() << "any type of data";
或O.C("any type of data");
相当于std::cout
流。这次支线旅行是为了让我知道它是否被使用。
// the obvious, shows and opens a/the console window so I can use the cout and cin streams.
void ShowConsole() {
AllocConsole();
HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
int hCrt = _open_osfhandle((long) handle_out, _O_TEXT);
FILE* hf_out = _fdopen(hCrt, "w");
setvbuf(hf_out, NULL, _IONBF, 1);
*stdout = *hf_out;
HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
hCrt = _open_osfhandle((long) handle_in, _O_TEXT);
FILE* hf_in = _fdopen(hCrt, "r");
setvbuf(hf_in, NULL, _IONBF, 128);
*stdin = *hf_in;
}
从那里,我不知道该怎么办。为了简单起见,我正在编写的类全局定义为"O"。函数C()
是我尝试用来使用流的函数。
我不知道在这里该怎么办,要么想办法用C()
返回句柄,要么想办法让C()
接受任何类型的数据。
该类是基本的,看起来像:
class testout {
private:
bool display;
public:
void ShowConsole();
void C(); // which could return a handle, or accept any data type
}
任何帮助都值得赞赏,我也可能在地方使用了一些不正确的术语。
我想
我不妨手动输入类型。
void testout::TOUT(int i) {cout << i;}
void testout::TOUT(double d) {cout << d;}
void testout::TOUT(char c) {cout << c;}
void testout::TOUT(char* cstr) {cout << cstr; }
void testout::TOUT(string str) {cout << str; }
在类中,对于这些函数,我将另外附加显示的 true 更新。
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 多态性和功能结合
- 带内存和隔离功能的SQLite
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- std::cout.imbue()多重调用
- 类模板的成员功能的定义在单独的TU中完全专业化
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何在C++中获得"静态纯虚拟"功能?
- 两个文件使用彼此的功能-如何解决
- 错误:在尝试检测 std::cout 是否<< t 时,功能强制转换为数组类型;有效
- Cuda 基本程序 (将值写入矩阵和 std:cout 不起作用) ;主功能不启动
- 尽管我的功能和cout语句的放置错误,但我的程序为什么会起作用
- & 字符在重载 std::cout 中的功能是什么?
- 为什么COUT在朋友函数中不起作用,该功能超载了操作员&lt;&lt;这是一个iStream运算符
- C++在主功能之外使用"cout"?
- std::cout 可防止功能中的段错误
- 具有类功能的cout
- Win32 C++从类返回 cout 功能
- std::cout功能的特殊行为