unsigned int command = 4;
cout << command;
command = (command << 1);
cout << command;
command = (command << 1);
cout << command;
输出:
4
8
10
为什么最后一行的输出是10
,而不是16
?
最佳答案
可能有一个 cout << hex
这段代码运行之前的某个地方。或者你不小心设置了cout
以十六进制格式化数字。如果你添加:
command = (command<<1);
cout << command;
它应该打印出 20
在十六进制模式下。
关于c++ - 移位数给出错误的输出 `std::cout`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7368200/