编译现象疑惑.~.~.~

xxmv99 2007-07-22 12:44:00
#include <iostream.h>

int main()
{
int x(10);
cout<<x<<endl;
return 0;
}
刚刚开始学C++,只是个环境测试程序,在g++ -o 1 1.cpp后总会有一大串提示:

In file included from /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/ios
tream.h:31,
from 1.cpp:1:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/backward_warning.h:32:2:
warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

编译能顺利通过,就是有点不爽,那大概意思也明白,就是不晓得怎么做哈,,,赐教.~
...全文
294 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzcwater 2007-07-24
  • 打赏
  • 举报
回复
....<iostream> instead of the deprecated header <iostream.h>.....
xxmv99 2007-07-24
  • 打赏
  • 举报
回复
哎...

要不再说一次:
#include <iostream.h>

int main()
{
int x(10);
cout<<x<<endl;
return 0;
}
这样编译是可以通过的,但有一串的提示,见1楼.

然后我试着去掉.h,即改为#include <iostream>,结果编译提示:`cout' undeclared (first use this function),然后我又将cout改为std::cout,endl改为std::endl,编译提示仍为:cout' undeclared (first use this function),大虾们,怎么回事呢?
xxmv99 2007-07-24
  • 打赏
  • 举报
回复
反正大概意思偶是明白了:包含时不需要.h~。

书上也说了这个规则,我很有印象,应该C是要的,和C有区别,所以记住了。

我用的cygwin,应该是编译器的问题了。

谢谢推荐用.net和Thinking in C++ V3/4~

结帖吧。
dadatech 2007-07-24
  • 打赏
  • 举报
回复
楼主选择的C++书太老了
那些书的说法还是C++刚出来时候的样子,和目前的标准相差甚远了。。。

推荐 Thinking in C++ V3(or V4)
woshiyizhiyu04 2007-07-24
  • 打赏
  • 举报
回复
还是用.net吧,在windows下面,这个编译器还是不错的。
woshiyizhiyu04 2007-07-24
  • 打赏
  • 举报
回复
.net下面:
写成
#include "stdafx.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
int x(10);
std::cout<<x<<std::endl;
return 0;
}
是可以的,我刚刚试过了。如果你是VC6.0的话,要用#include "iostream.h"
xxmv99 2007-07-24
  • 打赏
  • 举报
回复
大佬,我不是说了用#include <iostream>会提示:cout' undeclared吗?!!!

看了帖子再回,ok!?!?!
0黄瓜0 2007-07-23
  • 打赏
  • 举报
回复
两个在上海生活的人谈到"南京路",它们各自都知道是指的"上海南京路",那是因为它们预先加了
using namespace 上海;
0黄瓜0 2007-07-23
  • 打赏
  • 举报
回复
初学,书上怎么说,你就怎么做.

std称为名字空间.
举例说,上海有个"南京路",台北也有个"南京路"
两个在上海生活的人谈到"南京路",它们各自都知道是指的"上海南京路",
两个在台北生活的人谈到"南京路",它们各自都知道是指的"台北南京路",
但当一个台北人和一个上海人在巴黎谈论"南京路",如果不加上海或台北限定就会误会,上海人以为在谈"上海南京路",台北人以为在谈"台北南京路".
给"南京路"加上的"上海"(或"台北")称为"南京路"的名字空间,C++语法表示为
上海::南京路
台北::南京路

xxmv99 2007-07-23
  • 打赏
  • 举报
回复
好像没有什么吧
shuangfeiyiyu 2007-07-22
  • 打赏
  • 举报
回复
如果真的是学习c++,就按照标准来吧, 就如包含头文件这样的格式问题,标准就说的很清楚了。 呵呵
a3950410 2007-07-22
  • 打赏
  • 举报
回复
的确 的确
abfahren2000 2007-07-22
  • 打赏
  • 举报
回复
完整的是
#include <iostream>
using namespace std;
xxmv99 2007-07-22
  • 打赏
  • 举报
回复
顶起来哈...

xxmv99 2007-07-22
  • 打赏
  • 举报
回复
对啊,标准是不要.h的,可是这样会:
`cout' undeclared (first use this function)

加std::效果一样啊...

奇怪了...
Inhibitory 2007-07-22
  • 打赏
  • 举报
回复
#include <iostream.h> // 提示这种头文件的用法已经不推荐使用了,而应该用#include <iostream>

int main()
{
int x(10);
cout<<x<<endl;
return 0;
}
星羽 2007-07-22
  • 打赏
  • 举报
回复
#include <iostream>

using namespace std;

int main()
{
int x(10);
cout<<x<<endl;
return 0;
}

或者

#include <iostream>

int main()
{
int x(10);
std::cout<<x<<std::endl;
return 0;
}

69,370

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧