感谢您花时间阅读我的问题。所以我有这个代码:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
float pricePerLetter = 0.0;
string userInput;
cout << "Welcome" << endl;
cout << "Please enter sentence: ";
getline(cin, userInput);
cout << userInput;
cout << "Please enter price per letter: ";
cin >> pricePerLetter;
cout << endl;
system("PAUSE");
return 0;
}
运行正常。我能够在userInput上保存句子并显示它。但是,当我为下面的代码切换代码的片段时,程序结束而不让我写句子。
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
float pricePerLetter = 0.0;
string userInput;
cout << "Welcome" << endl;
cout << "Please enter price per letter: ";
cin >> pricePerLetter;
cout << endl;
cout << "Please enter sentence: ";
getline(cin, userInput);
cout << userInput;
system("PAUSE");
return 0;
}
我不明白为什么会这样。