これはおそらく非常に単純な問題ですが、私が新しいものとして私を許します。ここ は私のコードです:getlineは入力を求めていませんか?
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string name;
int i;
string mystr;
float price = 0;
cout << "Hello World!" << endl;
cout << "What is your name? ";
cin >> name;
cout << "Hello " << name << endl;
cout << "How old are you? ";
cin >> i;
cout << "Wow " << i << endl;
cout << "How much is that jacket? ";
getline (cin,mystr);
stringstream(mystr) >> price;
cout << price << endl;
system("pause");
return 0;
}
問題がhow much is that jacket?
のgetlineを尋ねられたときの入力をユーザーに尋ねると、ちょうど「0」の初期値を入力しないことです。どうしてこれなの?
注:これは何度も要求されています。ここにいくつかいくつかのhttp://stackoverflow.com/questions/3731529/program-is-skipping-over-getline-without-taking-user-input http://stackoverflow.com/questions/1744665/need-help- with-getline http://stackoverflow.com/questions/4876959/ignore-spaces-using-getline-in-c – cpx