CIN正在吞噬输出流
cin is eating output stream
#include <iostream>
using namespace std;
void main(int argc, char* argv[])
{
int conversion, hash;
cout << "Select one." << endl;
cout << "0: Radix Method 32" << endl;
cout << "1: Radix Method 64" << endl;
cout << "2: SumUp" << endl;
cin >> conversion;
cout << endl << "Select one." << endl;
cout << "0: Division" << endl;
cout << "1: Multiplication" << endl;
cin >> hash;
cout << "Conversion: " + conversion << endl;
cout << "hash: " + hash << endl;
}
就这么简单,我得到了疯狂的输出。 我觉得这是显而易见的,但我太累了,看不到它。 我在变量中输入的数字是从下一个输出字符串中删除的字符数。 前任:
Select one.
0: Radix Method 32
1: Radix Method 64
2: SumUp
1
Select one.
0: Division
1: Multiplication
2
onversion:
sh:
Press any key to continue . . .
Select one.
0: Radix Method 32
1: Radix Method 64
2: SumUp
5
Select one.
0: Division
1: Multiplication
1
rsion:
ash:
Press any key to continue . . .
我是疯了还是这毫无意义?我用错cin
了吗? 我已经几个月没有使用C++了,但我看不出有什么问题。
cout << "Conversion: " + conversion
表示从数组头部之后的conversion
元素打印。
您可能希望这样做(将+
更改为<<
):
cout << "Conversion: " << conversion << endl;
cout << "hash: " << hash << endl;
相关文章:
- 如何在C++中编写 ostream 的向量,它接收所有不同的输出流,如 cout、ostringstream 和 ofs
- 在输出流中插入换行符
- 在类外部重载输入和输出流
- 通用容器的输出流
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- 使输出流式处理运算符适用于 boost::variant<std::vector<int>、int、double 的正确方法是什么>
- 获取C++输出流中元素的大小
- 用于了解输入和输出流缓冲区实际工作方式的程序
- 控制多线程程序中的输出流
- 为什么输出流首选" "而不是""?
- C++ 输出流运算符 <<() 中的字符何时加宽?
- 音频缓冲区列表,用于输出流格式已压缩的 AUHAL 单元
- 如何将值发送到标准输出流并在另一个程序中访问这些值
- 我必须如何将OpenCV输出流到我自己的远程C GUI
- 如何为提升日志和自定义类型定义输出流运算符
- 修改视频帧并将其发送回视频输出流
- 组合输入和输出流
- C++ 中的递增/递减和输出流运算符优先级
- C++输出流到文件不起作用
- CIN正在吞噬输出流