Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用cin. 如果我将输入留空(然后按回车键),光标将移动到新行并再次要求输入。在这种情况下,有没有办法制作cin或scanf只返回一个空字符串?
cin
scanf
而不是operator>>,使用getline。
operator>>
std::string data; std::getline(std::cin, data);
旁注:这里不涉及递归。递归是当一个函数调用自己时,这不会发生在这里。