getline no solicita información? [duplicar
Esta pregunta ya tiene una respuesta aquí:
Necesita ayuda con getline () 7 respuestasEste es probablemente un problema muy simple, pero perdóname porque soy nuevo. Aquí está mi código:
#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;
}
El problema es que cuando se le preguntahow much is that jacket?
getline no solicita al usuario la entrada y solo ingresa el valor inicial de "0". ¿Por qué es esto