2014-01-07 41 views
-2

我正在使用C++編寫程序。打印歸檔到屏幕的功能

我想打印文件的結果稱爲打印(),只能打印到屏幕。

results->Print(); // this print to console I want it to print this information to a file. 

是能夠將定義的方法的標準輸出重定向,而不改變它?

最好的問候, 豪爾赫·洛佩斯

+1

請給我們的代碼。 – 0x499602D2

+2

http://stackoverflow.com/questions/10150468/how-to-redirect-cin-and-cout-to-files這可能有幫助 – user1950929

+1

當你要調用你的程序時,你可以從shell重定向輸出。這是依賴於操作系統,雖然... –

回答

0

例如

std::ostream & Print(std::ostream &os = std::cout) const; 

和函數體替代所有std::coutos內。

+0

我認爲這不會起作用,因爲「沒有改變它」。 –

+0

我無法更改該方法。 –

+0

@John Dibling不認真,因爲它不可能不改變功能。 –