getline(cin,string1)问题 [英] getline ( cin, string1) problem
本文介绍了getline(cin,string1)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
请帮我解决这个奇怪的问题.每当我在代码中调用多个getline(cin,string1)函数时,它们中的一些都会在运行时被跳过,即不提示用户输入,程序只是跳到另一行,例如
getline(cin,string1);
getline(cin,string2);
永远不会提示用户输入string1.仅提示用户输入字符串2.
Hi all,
Please, help me with this strange problem. Whenever I invoke more than one getline(cin, string1) function in my codes, some of them are skipped at run-time i.e. the user is not prompted for input and the program simply jumps to another line e.g.in
getline (cin, string1);
getline (cin, string2);
The user is never prompted for string1. The user is only prompted for string2.
推荐答案
您可以尝试在getline(cin, string1);
之前调用cin.ignore();
(如果输入缓冲区中有虚假的换行符) .
:)
You may try to callcin.ignore();
just beforegetline(cin, string1);
(if you have a spurious newline in the input buffer).
:)
这篇关于getline(cin,string1)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文