关于ostream。。。。

wxgiter 2009-03-11 07:47:49
[code=C\C++]
#include <iostream>
#include <string>

using namespace std;

int main()
{
ostream out;//为什么不行?
ostream &out(cout);//这个行,为什么?

system("pause");
return 0;
}[/code]

ostream为什么不能定义对象?如程序所示。。
IDE是dev-cpp。。
...全文
574 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzhen201 2011-10-09
  • 打赏
  • 举报
回复
在VC6.0里面,ostream类中的构造函数是作为私有成员出现的,所以不可以
公子姬良 2011-06-30
  • 打赏
  • 举报
回复
学习了下二楼。。。不过这个问题我也碰到过。
cardinaleaf 2009-03-11
  • 打赏
  • 举报
回复
学习了
beyond071 2009-03-11
  • 打赏
  • 举报
回复
学习下
  • 打赏
  • 举报
回复
2楼讲的很清楚了
jojotom 2009-03-11
  • 打赏
  • 举报
回复
学习了。
fairchild811 2009-03-11
  • 打赏
  • 举报
回复
ls都是正解
grellen 2009-03-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chin_chen 的回复:]
explicit ostream (streambuf * sb);
ostream没有默认的构造函数,必须给它赋值
ostream&out(cout);//这个是引用,不是构造,out现在…
[/Quote]
up
bfhtian 2009-03-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chin_chen 的回复:]
引用 1 楼 wxgiter 的回复:
C/C++ code#include <iostream>#include <string>usingnamespacestd;intmain()
{
ostreamout;//为什么不行?ostream&out(cout);//这个行,为什么?system("pause");return0;
}

ostream为什么不能定义对象?如程序所示。。
IDE是dev-cpp。。

explicit ostream (streambuf * sb);
ostream没有默认的构造函数,必须给它赋值
ostream&out(cout);//这个是引用,不是构造,out现在…
[/Quote]
up
chin_chen 2009-03-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wxgiter 的回复:]
C/C++ code#include<iostream>#include<string>usingnamespacestd;intmain()
{
ostreamout;//为什么不行?ostream&out(cout);//这个行,为什么?system("pause");return0;
}

ostream为什么不能定义对象?如程序所示。。
IDE是dev-cpp。。
[/Quote]
explicit ostream (streambuf * sb);
ostream没有默认的构造函数,必须给它赋值
ostream&out(cout);//这个是引用,不是构造,out现在是cout的别名了。注意区别一下。
wxgiter 2009-03-11
  • 打赏
  • 举报
回复
 
#include <iostream>
#include <string>

using namespace std;

int main()
{
ostream out;//为什么不行?
ostream &out(cout);//这个行,为什么?

system("pause");
return 0;
}


ostream为什么不能定义对象?如程序所示。。
IDE是dev-cpp。。

64,647

社区成员

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

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