c++小问题,请高手指点下新手!

songzhenxing1989 2008-06-30 09:32:24
为什么#include <iostream.h>不需要用using name space std;
而用#include <iostream> 不写using name space std;
会提示error C2065: 'cout' : undeclared identifier


#include <iostream.h>
void Change( int (*p)[3])
{
int temp;
for (int i=0; i<3; i++ )
{
for (int j=0;j<3; j++)
{
if(j>i)
{
temp = *(*(p+i)+j);
*(*(p+i)+j) = *(*(p+j)+i);
*(*(p+j)+i) = temp;
}
}
}
}
void main()
{
int i,j;
int arr[2][3] = {{1,2,3},{4,5,6}};
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<"开始转置..."<<endl;
Change(arr);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
}
...全文
73 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
macfan 2008-06-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 k2eats 的回复:]

<iostream>表示你使用的是标注命名空间,也就是在程序开始应该有这么一句话
using namespace std ;
这是遵循c++标准的
<iostream.h>
则没有遵循c++标准

[/Quote]

以上为正解.
K行天下 2008-06-30
  • 打赏
  • 举报
回复
参考百度知道:http://zhidao.baidu.com/question/29475316.html
<iostream>表示你使用的是标注命名空间,也就是在程序开始应该有这么一句话
using namespace std ;
这是遵循c++标准的
<iostream.h>
则没有遵循c++标准


而用#include <iostream> 不写using name space std;
会提示error C2065: 'cout' : undeclared identifier
因为cout在标准名称空间std中定义,也可以实用 using std::cout;
Gob00st 2008-06-30
  • 打赏
  • 举报
回复
建议lz看C++ premier第三版
yeliguo12345 2008-06-30
  • 打赏
  • 举报
回复
改过了
yeliguo12345 2008-06-30
  • 打赏
  • 举报
回复
#include <iostream.h>
void Change( int (*p)[3])
{
int temp;
for (int i=0; i <2; i++ )
{
for (int j=0;j <3; j++)
{
if(j>i)
{
temp = *(*(p+i)+j);
*(*(p+i)+j) = *(*(p+j)+i);
*(*(p+j)+i) = temp;
}
}
}
}
void main()
{
int i,j;
int arr[2][3] = {{1,2,3},{4,5,6}};
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
cout <<arr[i][j] <<" ";
}
cout <<endl;
}
cout <<"开始转置..." <<endl;
Change(arr);
for(i=0;i <3;i++)
{
for(j=0;j <2;j++)
{
cout <<arr[i][j] <<" ";
}
cout <<endl;
}
}




inlucde<iostream.h>
是老式的写法,现在应该都用include<iostream>
using namespace std;
应该每本书上都有介绍usnig namespace std;
表示的是命名空间,我也是初学

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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