this question has answer here:
- using getline(cin, s) after cin 10 answers
i have code: wish take in id, make sure it's of 8 chars in length, make sure each digit number, , continue ask until give correct input. before marks down, researched , tried @ answers given :c don't why says id enter 00000002 invalid id according code. it's not working. can help?
void student::getdata(){ string id_; cout << "lastname?" << endl; cin >> lastname; cout << "firstname?" << endl; cin >> firstname; cout << "id?" << endl; while(getline(cin,id_) && id_.size() != 8){ cout << "invalid id" << endl; }
while(getline(cin,id_) && id_.size() != 8){
here getline()
gets newline left on previous line of input. add line ignore rest of line before that.
cin.ingore(std::numeric_limits<std::streamsize>::max(), '\n'); while(getline(cin,id_) && id_.size() != 8){
Comments
Post a Comment