疯狂的基本 c++错误
谁能解释为什么 Codeblocks 给我这些错误?:
error: ISO C++ forbids declaration of 'cout' with no type
error: invalid use of '::'
error: expected ';' before '<<' token
error: '<<x>>' cannot appear in a constant-expression // <<x>> is many different variable names
我的代码实际上很简单:
#include <iostream>
#include "myclass.h"
int main(){
std::string data;
std::string e;
e = myclass().run(data);
std::cout << e << std::endl;
return 0;
}
世界上发生了什么?
编辑:是的,我确实有 iostream。抱歉没有早点把它放在那里
Can anyone explain why Codeblocks is giving me these errors?:
error: ISO C++ forbids declaration of 'cout' with no type
error: invalid use of '::'
error: expected ';' before '<<' token
error: '<<x>>' cannot appear in a constant-expression // <<x>> is many different variable names
my code is literally as simple as:
#include <iostream>
#include "myclass.h"
int main(){
std::string data;
std::string e;
e = myclass().run(data);
std::cout << e << std::endl;
return 0;
}
what in the world is going on?
EDIT: and yes, i do have iostream. sorry for not putting it there earlier
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
添加
std::cout
在此标头内编辑:关于您的编辑 - 这意味着问题肯定在
myclass.h
内,或者有一些代码,但不是此处显示。Add
std::cout
is inside this headerEDIT: regarding your edit - this means, that the problem is for sure inside
myclass.h
or there's some code, that is not shown here.#include
怎么样?没有它(和以下代码)
我的 g++ 报告:
How about
#include <string>
?Without it (and the following code)
my g++ reports :
您应该包含
you should include
<iostream>
您是否在某处包含了
?知道您已添加
后进行编辑,您可以检查:
#include
如果一切正常我想检查你的 myclass.h :-(
Did you include
<iostream>
somewhere?EDIT after knowing that you have added
<iostream>
Well you can check:
#include <string>
If everything is OK I want to check your myclass.h :-(
您发布的代码(带有编辑)是正确的。一定有
myclass.h
中发生了一些有趣的事情。 (也许是一个,以便编译器看到
::cout
。)您可能想查看预处理器输出:
Unix 下的编译器选项
-E
,Visual Studio 下的/E
。它将会很长,但您感兴趣的只是最后 10 条
左右线;预处理器对您的代码做了什么。
The code you post (with the EDIT) is correct. There must be
something funny going on in
myclass.h
. (Maybe a, so that the compiler sees
::cout
.)You might want to have a look at the pre-processor output:
compiler option
-E
under Unix,/E
for Visual Studios. Itwill be voluminous, but all you're interested in is the last 10
or so lines; what the pre-processor has done to your code.