這可能是一個非常簡單的問題,但請原諒我,因為我是新人。這是我的代碼:#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”。為什么是這樣?
getline不要求輸入?
慕蓋茨4494581
2019-09-06 15:41:53