我想在variable - number中输入一个11位数字,但我认为内存不是很大。我尝试使用*number and int *number = new int100,但它不起作用。
我还想在变量名中添加name和lastname,但每次我使用空格时,它也停止工作。
我该如何解决这些问题呢?
#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];
}
}发布于 2019-05-15 08:07:24
您当前正在使用带符号整数来保存您的值。
int number;带符号的整型最大值为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;https://stackoverflow.com/questions/56140111
复制相似问题