gpt4 book ai didi

c++ - getline 不要求输入?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:37 25 4
gpt4 key购买 nike

<分区>

这可能是一个非常简单的问题,但请原谅我,因为我是新手。这是我的代码:

#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;
}

问题是当询问那件夹克多少钱?时,getline 并不要求用户输入,只是输入初始值“0”。这是为什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com