为什么我的输出与输入不同?(C++)

Why is my output different from input? (C++)

本文关键字:C++ 我的 输出 输入 为什么      更新时间:2023-10-16

输入:7182933164 输出 : 2147483647 (不是我知道缺少的所有代码

}(
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream file("Numbers.txt");
int num;
cout << "Enter credit card number : " << endl;
cin >> num;
cout << "enterned : " << num << endl;

改用std:: string来表示代码号。

7182933164的值是如此之大,以至于它超过了它可以容纳的整数的值(即-2147483648 to 2147483647(。使用long类型修饰符接受此类值。如果只需要正整数,请在long之前添加unsigned.

执行以下操作:

...
long num; // dependent upon the computer architecture
...

如果这不起作用,请尝试long long。尽管它在OnlineGDB中运行良好(示例(。