| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6478 人关注过本帖
标题:在C++编程里,什么时候用“#include<iostream> using namespace std;”?什 ...
只看楼主 加入收藏
bc574479449
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-10-18
结帖率:100%
收藏
已结贴  问题点数:0 回复次数:9 
在C++编程里,什么时候用“#include<iostream> using namespace std;”?什么时候又用“#include <
(一)、#include <iostream.h>
using namespace std;
class point
{
public:point(int x1=0,int y1=0):x(x1),y(y1){}
       friend ostream& operator<<(ostream&, const point&);
      
       friend istream& operator>>(istream&,point&);
       int x,y;     
};
ostream& operator<<(ostream& out, point& src)
{
    out<<"<"<<src.x<<","<<src.y<<">";
    return out;
}
istream& operator>>(istream& in,point& target)
{
    in>>target.x>>target.y;
    return in;
}
int main()
{
    point a(1,2);
    cin>>a;
    cout<<a;
    return 0;
}
(二)、#include <iostream.h>
class point
{
    int x,y;
public:
    point(int x1=0,int y1=0):x(x1),y(y1){}      
    friend ostream& operator<<(ostream&, const point&);     
    friend istream& operator>>(istream&, point&);
};
ostream& operator<<(ostream& out, const point& src)
{
    out << "<" << src.x << "," << src.y << ">";
    return out;
}

istream& operator>>(istream& in,point& target)
{
    in>> target.x >> target.y;
    return in;
}
int main()
{
    point a(1,2);
    cin>>a;
    cout<<a;
    return 0;
}
为什么换个头文件“#include <iostream.h>”成
(二)就能够运行!??
搜索更多相关主题的帖子: std using include iostream 
2010-11-01 14:25
bc574479449
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-10-18
收藏
得分:0 
在C++编程里,什么时候用“#include<iostream> using namespace std;”?什么时候又用“#include <iostream.h>”?
2010-11-01 14:26
gaoce227
Rank: 4
来 自:山东
等 级:业余侠客
帖 子:134
专家分:218
注 册:2008-4-5
收藏
得分:5 
#include<iostream.h>//C的头文件
#include<iostream>//C++的头文件

using namespace std;//使用命名空间


2010-11-01 14:52
小鱼漂流
该用户已被删除
收藏
得分:4 
提示: 作者被禁止或删除 内容自动屏蔽
2010-11-01 20:46
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:3 
推荐在任何时候都用:
#include <iostream>
using namespace std;
后面那个 using 語句,如果不想引入 std 名空间的话,就不要用。之后用里面东西的时候加上名空间限定就行了,像 std::cin 这样。
2010-11-01 20:51
jookmmmm
Rank: 2
等 级:论坛游民
帖 子:9
专家分:27
注 册:2010-10-23
收藏
得分:0 
编译器问题
2010-11-02 23:09
qshzh102
Rank: 2
等 级:论坛游民
帖 子:19
专家分:20
注 册:2010-9-14
收藏
得分:3 
只需要将(一)中的头文件换成#include<iostream> using namespace std;即可
2010-11-03 14:50
weiqiang
Rank: 2
等 级:论坛游民
帖 子:48
专家分:52
注 册:2010-10-18
收藏
得分:0 
C++中最好用#include <iostream>
using namespace std;
2010-11-03 15:27
ytfsksk
Rank: 1
等 级:新手上路
帖 子:3
专家分:5
注 册:2010-11-3
收藏
得分:5 
#include "iostream"
using namespace std;
class point
{int x,y;
public:
       point(int x1=0,int y1=0):x(x1),y(y1){}
       friend ostream& operator<<(ostream&, const point&);
       friend istream& operator>>(istream&,point&);
};
ostream& operator<<(ostream& out, const point& src)
{ cout<<'<'<<src.x<<','<<src.y<<'>';
return out;
}
istream& operator>>(istream& in,point& target)
{ cin>>target.x>>target.y;
return in;
}
int main()
{point a(1,2);
cout<<"请输入:"<<endl;
cin>>a;
cout<<a;
return 0;
}
这个不是标准库引用的问题,这两种没有很大的区别看个人习惯。使用命名空间,最好用最新编译器
2010-11-03 17:04
swp160108
Rank: 2
等 级:论坛游民
威 望:4
帖 子:63
专家分:98
注 册:2008-11-10
收藏
得分:0 
vc6对std支持不太好
2010-11-05 09:27
快速回复:在C++编程里,什么时候用“#include<iostream> using namespace std;” ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028147 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved