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

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -