设为首页 加入收藏

TOP

Linux下C++编译出错原因解析
2014-11-23 21:52:05 来源: 作者: 【 】 浏览:16
Tags:Linux 编译 出错 原因 解析

Linux下C++编译出错原因解析


程序:
#include
int main()
{
cout << "hello world" << endl;
}

编译出错:
$ g++ s.cpp -o s.out
s.cpp: In function `int main(int, char**)':
s.cpp:12: error: `cout' was not declared in this scope
s.cpp:12: error: `endl' was not declared in this scope

原因:
C++ 1998 要求cout and endl被调用使用'std::cout'和'std::endl'格式,或using namespace std;

修改后:
#include
int main()
{
std::cout << "hello world" << std::endl;
}


#include
using namespace std;
int main(int argc, char *argv[])
{
cout << "hello world" << endl;
}

编译通过。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Ubuntu7.04 编译内核2.6.22.1 下一篇Linux中建立文件名时添加当前系统..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: