手机版
你好,游客 登录 注册
背景:
阅读新闻

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

[日期:2007-08-14] 来源:Linux公社  作者:Linuxidc [字体:大 中 小]

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;
}

编译通过。

linux
相关资讯       C++ 
本文评论   查看全部评论 (2)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 2 楼
* rachel 发表于 2011/5/17 9:13:42
顶~3Q
第 1 楼
* mm 发表于 2010/12/21 13:40:05
#include <iostream>
int main()
{
std::cout << "hello world" << std::endl;
return 0;
}


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