我想在变量中输入一个11位数的数字-数字,但我认为内存不足。我尝试使用* number和int * number = new int [100],但无法正常工作。
我也想在变量中添加name和lastname-name,但是每次我使用空格时,它也会停止工作。
我该如何解决这些问题?
#include <iostream>
#include <string>
using namespace std;
struct NOTE {
string name;
int number;
int birthday[3];
};
int main()
{
//int *tel = new int[100];
//int *ptr = new int;
NOTE arr[3];
cout << "Please enter quality names and numbers or program stop working!";
for (int i = 0; i < 3; i++) {
cout << "Man #" << i + 1 << "\n";
cout << "Name: ";
cin >> arr[i].name;
cout << "Number: ";
//*tel = arr[i].number;
//cin >> *tel;
cin >> arr[i].number;
cout << "Year: ";
cin >> arr[i].birthday[0];
cout << "Month: ";
cin >> arr[i].birthday[1];
cout << "Day: ";
cin >> arr[i].birthday[2];
}
}
答案 0 :(得分:3)
您当前正在使用带符号的整数来保存您的值。
int number;
一个带符号的int可以容纳2 ^ 31(2,147,483,648)的最大值,只有10位数字长。
unsigned int number;
无符号整数可以容纳2 ^ 32,即4,294,967,296(仍然是10位数字),这仍然不够。
您可以使用带符号的长整数,它的长度为64位,最多可以容纳2 ^ 63(9,223,372,036,854,775,808),即19位数字。这样就足够了。
long number;