cin>> not work with getline()
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: #include #include using namespace std ; int main () { string str ; int age ; cout << "Please enter age: " ; cin >> age ; cout << "Please enter full name: " ; getline ( cin , str ); cout << "Thank you, " << str << ".\n" ; } Why function getline() not work when I using uperator >> to input integer ? What is better use for int input ? 回答1: You still have a newline in the stream after cin>>age; , which is giving you an empty string for the name. You could solve it by just adding another getline() call after getting the age and throwing