getline的问题

mountain310 mountain310 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
本人菜鸟,发现程序运行并未按照编写代码的意图,即:输入quotation,回车一次,窗口提示输入speaker,然后键入speaker,回车,窗口显示输入的全部内容。 程序执行时,输入quotation之后,要回车两次才出现下一行提示;且程序直接执行到最后。。。。。。。
我那行代码cin.get();没有作用了 反复改动过发现是getline的问题 请各位大神明示~~

#include <iostream>

#include <string>

using namespace std;

int main(){

//declaring the necessary variables
string quote, speaker;

//prompt user for quotation
cout << " please enter the quotation:\n";
getline(cin, quote);

//promt user for the quote's author
cout << "enter the person to whom this quote is atrributed:\n";
getline(cin, speaker);

cout << "\n\n";

cout << "press enter or return to continue.\n";
cin.get();

return 0;

}
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
mountain310
C++ 语言 65,214 成员 250,514 内容