2013-12-17 164 views
-3

首先,我已经查找了解决方案,我似乎无法修复它。当试图编译源代码时,我得到以下错误。错误:未定义标识符“ostream”

g++ -c -I/home/jcallahan/ACM/include/FANSI -I/home/jcallahan/ACM/FourtyTwo/Base -I/home/jcallahan/ACM/FourtyTwo/FunctionSpaces -I/home/jcallahan/ACM/FourtyTwo/MeshLib LagrangeFunctions.cpp In file included from /home/jcallahan/ACM/include/FANSI/MatrixVector.h:6:0, from LagrangeFunctions.cpp:17: /home/jcallahan/ACM/include/FANSI/Matrix.h:184:24: error: ‘ostream’ has not been declared void WriteToTextFile(ostream &) ;

该错误是从包括Matrix.hVector.h未来(I有更多的这些错误只示出一个)。我相信错误在Matrix.h/Vector.h。代码被切断了,因为我不认为类成员函数与它有任何关系。

#include "AbstractMatrix.h" 

class Matrix : public AbstractMatrix 
{ 
    friend std::ostream &operator<<(std::ostream &,const Matrix &) ; 
    friend std::istream &operator>>(std::istream &, Matrix &) ; 
public: 

任何人都有任何线索怎么回事或我该如何解决它?有关其他信息,我正在使用g ++编译器。

+1

加上'#包括'到您的文件 – Mgetz

+1

的顶部看来你的头一个使用'ostream'无资质('的std ::'),并没有合适的'using'声明或'using'指令。与资格无关,合适的标题(''或'')也可能会丢失。 –

+0

Mgetz, 我加入了include,它没有改变任何东西。 Dietmar, 我没有在任何头文件中使用“命名空间标准”,但只有这一个给我一个问题。当编译使用PGI编译器时,它编译时没有问题 – jgCallahan

回答

2

你贴应包含此行的文件:

#include <iostream> 

此外,错误消息包括这样的定义:

void WriteToTextFile(ostream &) ; 

,需要加以改变以std::ostream其他人一样。

+0

在头文件中?我认为这是一个不允许把它们放在头文件中? – jgCallahan

+0

您可能会将no-no与'using namespace std;'混淆,这是一个禁止放入头文件的禁止。 – rightfold

+0

这不是一个禁忌。其中一个声明使用'std :: ostream',所以包含它是非常重要的。 – s4y

相关问题