【发布时间】:2018-06-25 19:21:30
【问题描述】:
所以,我正在尝试制作一个基本的 C++ 程序来转换 Base 10 -> Base 16
while(true){
int input;
cout << "Enter the base 10 number\n";
cin >> input;
cout << "The hex form of " << input << " is: ";
int decimal = input;
cout << hex << uppercase << decimal << "\n";
decimal = NULL;
input = NULL;
Sleep(3000);
}
在第一次运行时,它可以工作。例如,如果我输入 7331,我会得到:
The hex form of 7331 is 1CA3
但如果我第二次尝试(使用相同的输入)我会得到:
The hex form of 1CA3 is 1CA3
我可以尝试使用任何整数输入,它在第一次运行时运行良好,但之后它将基数为 16 的数字输入两次。
【问题讨论】:
-
这实际上不是我的代码,我只是想表明它包含在一个循环中。让我解决
-
Close-voter:这有什么不清楚的地方?我发现这个问题很清楚,OP 提到了他们的输入、输出和他们的期望。这个例子或多或少是完整的。
-
有些流操作符是sticky,有些不是。
std::hex是粘性。 -
避免
using namespace std