我有一個用C++編寫的程序,要求用戶輸入他/她的11位數字 手機號碼。但是當我輸入11位數字時,程序continue
沒有 執行後面的代碼。當輸入超過11個整數時C++程序終止
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;
}
感謝您告訴我們。有問題嗎? –
我猜是因爲你忘記了你廣泛使用的cin.ignore。我會建議使用cin.getline()代替用戶輸入 - 並請:將數字不存入長變量,而是存儲爲字符串 – Najzero
電話號碼應該是字符串。 – Maroun