[操作疑難] c++ ostream 問題

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

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

有無辦法令到佢可以咁樣?
int main( ){
MyOutput out;
out << "Hello World" ;
// 最好 Wrap 晒 cout 嘅嘢
}

喺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

TOP

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

TOP