Explanation needed

so i exploring the documentation and i tackle something that very bother me
when i input in this program a character constant a or any.. i dont get an error.. although i should get because float price or int quantity should get a numeric value so why when i type 'a' 'b 'c' in this program its run ok

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  // stringstreams
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main ()
{
  string mystr;
  float price=0;
  int quantity=0;

  cout << "Enter price: ";
  getline (cin,mystr);
  stringstream(mystr) >> price;
  cout << "Enter quantity: ";
  getline (cin,mystr);
  stringstream(mystr) >> quantity;
  cout << "Total price: " << price*quantity << endl;
  return 0;
}
When you try to put the value into price or quantity via the stringstream, the operation just fails and leaves the variable alone.
tnx for the explanation zhuge.
Topic archived. No new replies allowed.