Questions tagged «istream»

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 …
105 c++  input  iostream  istream  c++-faq 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.