2014-03-01 133 views
-5

在我的教科书中,它说ifstream是一个istream从文件读取。后来下来的页面,旁边还有一个例子的评论:我不明白ifstream

ifstream ist(name.c_str()); // ist is an input stream for the file named name. 

我有点困惑的区别是什么ifstreamist()之间。

+8

'ifstream'是类型,'ist'是变量名。这是非常基本的东西。 – Rapptz

+1

'std :: ifstream'是一个类,'ist'是该类的一个实例。 – 0x499602D2

+0

我认为是变量名称。但他们的方式使它看起来像你不得不使用ist,我看到很多其他人使用它。这只是一个使用它的惯例吗? – UnworthyToast

回答

3

ist是您将使用的ifstream的实例。有一个类型 - ifstream - 可以是许多变量的类型。

您可能有istist2,ist3,xpto,它们全都是ifstream

ifstream是类型。