getline的问题

mountain310 2012-05-14 08:27:40
本人菜鸟,发现程序运行并未按照编写代码的意图,即:输入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;

}
...全文
67 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
mountain310 2012-05-14
  • 打赏
  • 举报
回复
求热心解答!!!
qq120848369 2012-05-14
  • 打赏
  • 举报
回复
远离VC6,珍爱生命。
mountain310 2012-05-14
  • 打赏
  • 举报
回复
漏掉了几行代码。。。。不好意思!!!
在cout << "\n\n";之后 还有几行代码:


cout << "the following quotation has been received as follow:\n" << quote << "\n-" << speaker <<"\n\n";

就是这行代码在程序中反映不出来
W170532934 2012-05-14
  • 打赏
  • 举报
回复
我这也是好的。
liangbch 2012-05-14
  • 打赏
  • 举报
回复
我这里是好的

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧