簡體   English   中英

fstream,ofstream,ostream,iostream之間的區別

[英]Difference between fstream, ofstream, ostream, iostream

我正在對C ++的入門級課程進行測驗,並且試圖理解一個問題。 在互聯網上搜索后沒有得到答案,所以我在這里。

Which of the following function declarations will accept either cout or a file stream 
object as its argument?

A. void output( fstream &outFile);  
B. void output( ofstream &outFile); 
C. void output( ostream &outFile);  
D. void output( iostream &outFile);

答案是C。

我知道fstream,ofstream,ostream,iostream之間的區別。

我不明白的是為什么所有其他選項都不能接受cout或文件流對象作為參數。

答案是否像ostream對象一樣簡單,其中包含能夠作為參數傳遞的數據(char等)?

任何信息將不勝感激。

答案是C。問題是關於繼承層次結構。 std::coutstd::ostream的實例。 所有其他函數都接受std :: ostream的子類,因此無法處理std::cout std::fstream可以傳遞給所有人,但問題在於兩者。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM