我的理解是客观的:
我想要显示的结果后
方案保持开放何乐而不为呢典型的c++方式?
#include
int main(void)
{
int i;
char ch;
std::cout<
std::cin.get(ch); // For testing enter a string at this step say "String"
/* The input to cin is line-buffered, so after reading &#39;S&#39; to ch,
* the remaining "tring" is still in the buffer.
*/
std::cout<
while(std::cin.get()!&#61;&#39;\n&#39;)
;;
/* cin.get() is an overloaded function in the istream class.
* If no arguments are passed to &#39;get()&#39; this function reads single next character
* In essence, we wait for the cin.get() to clear the buffer that is
* read all characters including &#39;\n&#39;
*/
std::cout<
std::cin.get();
/* Since we have already cleared the buffer using the loop
* &#39;get()&#39; expects us to enter a character this time
*/
return 0;
}