3
为什么std :: getline()在格式化提取后会跳过输入?
我有以下代码提示用户输入名称和状态: #include <iostream> #include <string> int main() { std::string name; std::string state; if (std::cin >> name && std::getline(std::cin, state)) { std::cout << "Your name is " << name << " and you live in " << state; } } 我发现该名称已成功提取,但状态尚未提取。这是输入和结果输出: Input: "John" "New Hampshire" Output: "Your name is John and …