Type Casting in cin ( C++ ) -


    int x;      cout << "enter integer :: " << endl;     cin >> x ;     cout << "your value = " << x << endl;      cout << "enter float :: " << endl;     cin >> float (x) ;     cout << "your value = " << x << endl; 

the above code shows error. why can type cast in cout not in cin ?

a cast this:

  float(x) 

produces nameless temporary object of type float. >> operator looks this:

 istream & operator>>( istream &, float & f ); 

and can't bind non-const reference temporary.

the output operator looks this:

 ostream & operator<<( ostream &, const float & f ); 

and can bind const reference temporary, works.


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -