我写了以下功能
void validateUser(void)
{
string uName;
string uPassword;
char c;
map <char*, char*> authMap;
authMap["balaji"] = "balaji";
authMap["rohan"] = "rohan";
cout << "Please Enter your user name :";
cin >> uName;
cout << "Please Enter your password :";
// initTermios(0);
while((c = getchar()) != '\n')
{
uPassword.push_back(c);
}
cout << "YOU Entered :: "<< uPassword <<std::endl;
}
当我执行上述函数时,我发现输入用户名后我按下回车键然后控制不会进入while循环,即使我没有输入任何密码字符串。上面的蚂蚁解决方案?预先感谢。