我正在使用C++編寫程序。打印歸檔到屏幕的功能
我想打印文件的結果稱爲打印(),只能打印到屏幕。
results->Print(); // this print to console I want it to print this information to a file.
是能夠將定義的方法的標準輸出重定向,而不改變它?
最好的問候, 豪爾赫·洛佩斯
我正在使用C++編寫程序。打印歸檔到屏幕的功能
我想打印文件的結果稱爲打印(),只能打印到屏幕。
results->Print(); // this print to console I want it to print this information to a file.
是能夠將定義的方法的標準輸出重定向,而不改變它?
最好的問候, 豪爾赫·洛佩斯
例如
std::ostream & Print(std::ostream &os = std::cout) const;
和函數體替代所有std::cout
的os
內。
我認爲這不會起作用,因爲「沒有改變它」。 –
我無法更改該方法。 –
@John Dibling不認真,因爲它不可能不改變功能。 –
請給我們的代碼。 – 0x499602D2
http://stackoverflow.com/questions/10150468/how-to-redirect-cin-and-cout-to-files這可能有幫助 – user1950929
當你要調用你的程序時,你可以從shell重定向輸出。這是依賴於操作系統,雖然... –