与c++中应该输出的完全不同的输出

Completely Different Output Than What Should Be Output In c++

本文关键字:输出 c++      更新时间:2024-09-29

我制作了一个简单的c++程序,它接收两个数字,清除屏幕,然后将这两个数字的总和输出到终端窗口。它非常有效。键入5作为第一个数字,键入10作为第二个输出15。

但有一个问题。当运行程序时,第一个数字是5,第二个数字很长,例如:

3285720358162039587169230839461283795732948567123857690,

程序没有输出正确的数字,也没有显示用户键入的正确数字。

例如,当使用前两个数字时;sum";将为:-2147483644,此时它应该是末尾带有5而不是零的长数字。

这是我的代码:

#include <iostream>
int main() {
system ("clear");
int num1 = 0;
int num2 = 0;
std::cout << "What is the first number?: ";
std::cin >> num1;
std::cout << "What is the second number?: ";
std::cin >> num2;
system ("clear");
std::cout << "The sum of " << num1 << " and " << num2 << " is: " << (num1 + num2) << "n";
}

整数大小有限制~~你可能会将这些数字声明为长-长。~~

编辑:特德是正确的,长隆对于那个特定的输入来说也不够大。