C++输入超过 11 个整数时程序终止
C++ program terminate when entering more than 11 integer
我有一个用C++编写的程序,要求用户输入他/她的 11 位数字 手机号码。但是当我输入 11 位数字时,程序continue
没有 执行成功代码。
string FriendName, FriendAdd, EmailAdd;
long MobileNumber, counter, counter1, counter2;
//Create a new structure
struct personData {
string namePerson, addressPerson, emailAddress;
long age;
struct personData *next;
};
//Initialize pointers to personData structure
typedef struct personData node;
node *firstRec, *currentRec, *tempRec, *tempRec2;
void InsertRec() {
cin.ignore(200,'n');
cout<<"Enter your Friend's Name : ";
cin.ignore(1,'n');
getline(cin,FriendName);
cout<<"Enter your Friend's Mobile Number : ";
cin>>MobileNumber;
cout<<"Enter your Friend's Address : ";
cin.ignore(1,'n');
getline(cin,FriendAdd);
cout<<"Enter your Friend's Email Add : ";
getline(cin,EmailAdd);
cout<<endl<<endl;
tempRec = new(personData);
tempRec->namePerson = FriendName;
tempRec->addressPerson = FriendAdd;
tempRec->emailAddress = EmailAdd;
tempRec->age = MobileNumber;
tempRec->next=firstRec;
//firstRec->next=tempRec;
firstRec=tempRec;
}
整型类型的大小取决于目标平台和编译器设置。假设 long
是 32 位整数,则它仅支持 10 位数字。
32 位整数类型的最大值为:
签名:-2147483647 至 2147483647
无符号:0 到 4294967295
更好的方法是将手机号码存储为字符串,而不是数字。
这是您选择使用手机号码的数据类型问题。输入手机号码后,再次打印,看看它是否显示相同的值。您的 11 位数字值超出了long
限制。
电话号码不是整数,而是一串数字。
有符号整数(对于 32 位整数,使用的取决于平台和编译器)可以包含的最大数字为 +2,147,483,647。这是 10 位数字。
相关文章:
- 内联程序集printf将整数解释为地址
- 为什么有时我输入一个整数,程序将第一个输入的数字打印成十进制数?
- 如何将字符串和整数读取到两个单独的动态数组中的程序编写?
- 我正在尝试制作一个程序,在添加 n 天(整数)后告诉一个人什么是一天(例如星期一等)
- 编写一个读取五个整数并执行一些任务的C++程序
- 为什么这个程序接受整数和字母数字输入并打印它们? C++ 中的 std::string 也采用整数值吗?
- 16 位系统中的程序如何访问大于 65535 的整数,但不能访问地址
- 我需要编写一个程序来读取一个文件,该文件将输出所有唯一的整数,如果已经看到整数,它将被关闭
- 编写一个程序,提示用户输入一个整数,然后输出数字的单个数字和数字的总和
- 在控制台上输出我从文件中读取的整数,将程序插入无限循环
- 向文件读取和写入整数的程序
- MongoDB C++ 驱动程序 - 8 位和 16 位整数?
- 编写一个程序,输入整数 n 并打印该数字的字符数(符号除外)
- 我的程序不断四舍五入到最接近的整数
- 为什么在此C++程序上添加负整数会导致正整数?
- 调用 Parse int 函数时编译 parse 整数程序时出现问题
- C++程序,将整数输入转换为字符的问题
- 我的C++程序有问题.涉及动态调整整数数组的大小
- 程序终止,而不是继续整数输入验证循环
- 查找混合整数程序的绑定约束