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