这个C ++程序有什么问题? [英] What's wrong with this C++ program?
本文介绍了这个C ++程序有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编译此程式时:
#include<iostream>
using namespace std;
std::cout<<"before main"<<endl;
int main()
{
}
...我从编译器看到这个错误:
...I see this error from the compiler:
错误:expected constructor,
destructor类型转换
'<<'token
error: expected constructor, destructor, or type conversion before '<<' token
请帮助我理解这是什么意思, ?
Please help me understand what this means and what's wrong with my program?
推荐答案
您看到此错误,因为您的
You're seeing that error because your
std::cout<<"before main"<<endl;
语句需要在 main()
函数(或某些其他函数),以使此程序有效:
statement needs to be within the scope of your main()
function (or some other function) in order for this program to be valid:
int main()
{
std::cout<<"before main"<<endl;
}
与您的具体问题无关,另外一点: $ c>使用命名空间std ,在 std :: cout
上的显式 std ::
是多余的。
Unrelated to your specific question, one extra point: as you are using namespace std
, the explicit std::
on std::cout
is redundant.
这篇关于这个C ++程序有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文