【问题标题】:I don't understand ifstream [closed]我不明白 ifstream [关闭]
【发布时间】:2014-04-02 23:53:54
【问题描述】:

在我的教科书中,它说ifstream 是用于读取文件的istream。稍后在页面下方,示例旁边有一条评论:

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

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

【问题讨论】:

  • ifstream 是类型,ist 是变量名。这是非常基本的东西。
  • std::ifstream 是一个类,ist 是该类的一个实例。
  • 我认为 ist 是变量名。但他们的措辞方式让你看起来必须使用 ist,而且我看到很多其他人都在使用它。这只是使用它的约定吗?
  • @UnworthyToast 我会说它只是“输入流”的缩写
  • @UnworthyToast 我个人从未将ist 视为文件流的变量名。你可以使用你想要的,但我建议选择易于理解和简洁表达你意图的变量名。

标签: c++ iostream ifstream


【解决方案1】:

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

你可以有istist2ist3xpto,它们都是ifstream

ifstream 是类型。

【讨论】:

    猜你喜欢
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 2012-01-14
    • 1970-01-01
    • 2013-10-22
    • 2020-10-23
    • 1970-01-01
    相关资源
    最近更新 更多