hihocoder 练习 A+B
来源:互联网 发布:linux就该这么学 下载 编辑:程序博客网 时间:2024/05/16 08:51
题目就是输入两个数,求和,看起来挺简单的一个题,我尝试了cin.get()和cin >> ,
1,
#include<stdio.h>
#include<iostream>using namespace std;
int main()
{
int a, b;
a = cin.get();
b = cin.get();
cout << a + b << endl;
return 0;
}
结果出错;
2,
#include<stdio.h>
#include<iostream>using namespace std;
int main()
{
int a, b;
cin >> a;
cin >> b;
cout << a + b << endl;
return 0;
}
正确;
原因:
1,">>"输入时,空白字符会被跳过,但是cin.get不会跳过,,所以第一种方法我测试了1 2(1、空格、2),所以cin.get()的分别是1和空格,;
2,查了下变量a和b发现,保存的分别是49(数字1的ASCII),32(空格的ASCII),这是因为cin.get()用于字符输入;
3,如果将a = cin.get()改写成cin.get(a),则编译就会报错,“无法将int 转化成char”或者“没有与参数列表匹配的重载函数”,原因都是因为cin.get()用于字符输入
0 0
- hihocoder 练习 A+B
- hihoCoder 编程练习赛19 A, B
- hihoCoder #1000: A+B
- hihoCoder 1000 A+B
- HihoCoder--A+B解答
- hihoCoder小试牛刀A+B
- hihoCoder之#1000 : A + B
- 开启hihocoder之旅(A+B)
- hihoCoder #1000:A+B (大整数)题解
- hihocoder #1000 : A + B Java实现
- 寒假练习 1000 A+B
- PAT练习-部分A+B
- PAT练习-A除以B
- ACM 1000A+B Problem 练习
- 2013寒假练习 1000:a+b
- BIT寒假练习-2013__1000:a+b
- ACM俱乐部练习-A+B without carry
- A+B输入输出练习系列 I
- Linux常用命令 经典版
- 正则表达式大全
- 正则表达式参考文档
- LeetCode 30. Substring with Concatenation of All Words
- Android 的快速开发框架XUtils
- hihocoder 练习 A+B
- Android动画常用公共属性详解
- 译--ToolBar(四)
- Windows DLL编程中的导入导出:__declspec(dllimport) ,__declspec(dllexport) ,
- NGUI PK UGUI
- Quartz Configuration Reference
- Ubuntu下shell脚本运行异常:bash和dash的区别
- 双亲委派模型的工作过程
- 谷歌注册失败 手机已多次注册