Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class thing{
- double something;
- public:
- thing(double d) : something(d) {}; //constructor with member initialization list
- friend istream& operator>>(istream&,thing&); //the istream operator overloading
- };
- istream& operator>>(istream& in,thing& t) //the definition of the operator overloading (global)
- {
- cout << "Write a number: "; //first we just write something to the user
- //you can do other thing in here as well (similarly to ostream), for example check the correctness of the entered data...
- in >> t.something; //then read it from in to something
- return in; //finally return with the istream
- }
- int main ()
- {
- thing t(5.5);
- cin >> t;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment