解释当整数作为输入时输出
Explain the output when a integer is given as input
-当整数是输入时解释输出
-为什么 -47 在输入为 5 时递增该值
#include <iostream>
using namespace std;
int main() {
string s;
cin>>s;
cout<<(*s.begin())-47;
}
return 0;
}
在 ASCII 字符 2 中,代码为 50。所以 50 - 47 将导致 3。因此,如果在语句中
cin>>s;
你被 2
然后在语句中
cout<<(*s.begin())-47;
等效于 '2' - 47
的表达式 *s.begin()-47
由于整数提升而转换为类型 int
并且等于 3 ( '2' - 47 => 50 - 47 == 3)。
考虑到调用s.begin()
返回指向字符串的第一个字符的迭代器,*s.begin()
生成字符本身。
相关文章:
- 字符的输入/输出操作
- C++ 中文件输入输出中的长长 v/s int
- 要求用户输入C++输出文件名
- 在C++中重载输入/输出运算符
- 从用户获取输入/输出
- 如何选择waveIn/waveOut函数C++使用的输入/输出设备
- C++击球平均值程序使用输入/输出文件打印名称,平均值,最高/最低平均值时遇到麻烦
- 从 2 位输入输出 4 位数字年份
- 标准输入输出操作如何C++完成
- Windows 中应用程序的每秒输入/输出操作数
- 如何初始化可以设置为默认数组并将输入/输出作为数组的类函数?
- 输入/输出和类
- 使用 Octave GNU 访问输入/输出文件
- (C++)分解这个简单的输入/输出代码:
- TensorFlow模型:如何从原始爱好文件中识别输入/输出节点名称
- 干净取消在输入/输出调用中被阻止的 std::线程
- 将线程之间的标准输入/输出重定向
- 输入/输出异或字符串的 C++ 问题
- C++输入/输出错误
- C++输入输出