免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2923 | 回复: 5
打印 上一主题 下一主题

[C++] 关于“endl”的用法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-02-21 14:21 |只看该作者 |倒序浏览
刚在学习中,菜鸟请教:
//Compute two integer's sum
#include <iostream>
using namespace std;

main()
{int a,b;
int sum;
cout<<"please enter one integer:"<<a<<endl;
cin>>a>>endl;
cout<<"please enter another integer:"<<b<<endl;
cin>>b>>endl;
sum=a+b;
cout<<"sum of the two integer is:"<<sum<<endl;
system("pause");
return 0;
}

为什么加上红色那两个“endl”就编译不过去呢?去掉则可以:shock:
visual c++6.0编译失败,Dev C++ 5也是
D:\VC++\sum.cpp(9) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)

[ 本帖最后由 灵犀一指 于 2008-2-21 14:24 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-02-21 15:25 |只看该作者
endl是一个ostream操纵符(manipulator),它把一个换行符插入到输出流中,然后刷新ostream缓冲区



完了,明白,菜鸟就是菜鸟

之前只把endl当成简单的换行

[ 本帖最后由 灵犀一指 于 2008-2-21 15:30 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2008-02-22 17:04 |只看该作者
cin>>endl
不错才怪

论坛徽章:
0
4 [报告]
发表于 2008-02-22 23:04 |只看该作者
希望各位多发表意见
谢谢:em11:

论坛徽章:
0
5 [报告]
发表于 2008-02-23 01:02 |只看该作者

论坛徽章:
0
6 [报告]
发表于 2008-02-26 11:45 |只看该作者
>>endl
不错才怪
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP