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