为了账号安全,请及时绑定邮箱和手机立即绑定

getline不要求输入?

getline不要求输入?

C++
慕盖茨4494581 2019-09-06 15:41:53
这可能是一个非常简单的问题,但请原谅我,因为我是新人。这是我的代码:#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”。为什么是这样?
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 493 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号