Board logo

標題: [操作疑難] c++ ostream 問題 [打印本頁]

作者: ghostkcleung    時間: 2022-2-3 05:37     標題: c++ ostream 問題

我有一件嘢,裡面有個 putchar(int ch) 如下:

class MyOutput {
  public:
    int putchar(int ch) { /*...*/ }
}

有無辦法令到佢可以咁樣?
int main( ){
MyOutput out;
out << "Hello World" ;
// 最好 Wrap 晒 cout 嘅嘢
}
作者: antlee    時間: 2022-2-3 17:12

喺C++ "<<" 係一個operator, 大概做法可以 google
"ostream operator overloading c++"

https://docs.microsoft.com/en-us ... asses?view=msvc-170
https://stackoverflow.com/questi ... ator-for-an-ostream
作者: ghostkcleung    時間: 2022-2-3 23:37

我試緊 inherit ostream,
override put ()
Compile 到無 error,
不過未試 run ...





歡迎光臨 電腦領域 HKEPC Hardware (https://h0.hkepc.com/forum/) Powered by Discuz! 7.2