【问题标题】:ifstream C++ not recognized [closed]ifstream C++无法识别[关闭]
【发布时间】:2014-06-13 00:12:56
【问题描述】:

我正在用 C++ 修改一个程序,我需要将一些值写入磁盘。

我在“包含”部分添加了#include <fstream>,然后我尝试使用ifstream,但无法识别:

IntelliSense:标识符“ifstream”未定义

我做错了什么? 谢谢,

编辑: 这是代码

#include <fstream>
#include "stdafx.h"
#include "CommandHandling.h"
#include "Conversions.h"
#include "INIFileRW.h"
#include "ComPortTimeout.h"

CCommandHandling::CCommandHandling()
{
    /* set up com port class, start from new. */
    pCOMPort = NULL;
    pCOMPort = new Comm32Port;
    ifstream test; //Here I get the error cited above
... //More code here
...
...
...

}

【问题讨论】:

  • 它在std 命名空间中?
  • 可能有助于展示您如何使用它。
  • 可能还需要#include &lt;istream&gt;(通常 fstream 包括 istream 但不能保证)
  • 您发布的代码没有显示任何 fstreams
  • using namespace std; @chris 没有建议!不要这样做;这是一个坏习惯,将来在编写有意义的代码时可能会导致命名空间冲突。您将希望在几乎所有情况下都使用完全限定名称,直到您尝试在遥远的将来某个时候降低已出版书籍中的墨水成本。它有可能在更有意义的代码中引起命名冲突/冲突。使用std:: 作为前缀。 std::fstreamstd::stringstd::cout

标签: c++ ifstream


【解决方案1】:

没有看到您的代码,我无法确定,但我会尝试的第一件事是查看它是否接受std::ifstream

如果是这样,那么熟悉 C++ 中的命名空间可能是值得练习的——它们无处不在。你无法避免它们。 (不是我建议你应该想要!)

【讨论】:

  • std::ifstream 在我的代码中工作..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-08
  • 1970-01-01
  • 2017-11-19
  • 1970-01-01
  • 1970-01-01
  • 2015-04-29
  • 2017-05-18
相关资源
最近更新 更多