cin

Using getline(cin, s) after cin

旧巷老猫 提交于 2019-11-25 21:57:13
问题 I need the following program to take the entire line of user input and put it into string names: cout << \"Enter the number: \"; int number; cin >> number; cout << \"Enter names: \"; string names; getline(cin, names); With the cin >> number command before the getline() command however (which I\'m guessing is the issue), it won\'t allow me to input names. Why? I heard something about a cin.clear() command, but I have no idea how this works or why this is even necessary. 回答1: cout << "Enter the