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.
我需要从输入中获取一些行。这些行可能包含空格。我写了代码:
string s; for (i = 0; i < n; ++i){ getline(cin, s); //after this i have '\n' in buffer, and it refers to TRASH AND SODOM(( }
这不起作用;如何清除缓冲区?
std::cin.ignore(INT_MAX)和std::cin::clear()。我认为简单得多?
std::cin.ignore(INT_MAX)
std::cin::clear()