与c++中应该输出的完全不同的输出
Completely Different Output Than What Should Be Output In c++
我制作了一个简单的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";
}
整数大小有限制~~你可能会将这些数字声明为长-长。~~
编辑:特德是正确的,长隆对于那个特定的输入来说也不够大。
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 为什么rk4.do_step不输出C++中的初始条件
- 输出没有重复元素的动态数组(收缩数组)C++
- 如何根据单词在文本中出现的概率输出单词