Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class book {
- string title;
- string author;
- double price;
- public:
- friend istream& operator>> (istream& in, book& b);
- friend ostream& operator<< (ostream& out, book& b);
- };
- istream& operator>> (istream& in, book& b) {
- cout << "Enter title: ";
- getline(in, b.title);
- cout << "Enter authoe: ";
- getline(in, b.author);
- cout << "Enter price: ";
- in >> b.price;
- in.ignore(37578, '\n');
- return in;
- }
- ostream& operator<< (ostream& out, book& b) {
- out << "Title: " << b.title << endl;
- out << "Author: " << b.author << endl;
- out << "Price: " << b.price << endl;
- return out;
- }
- int main() {
- book b;
- cout << "Enter info about book: " << endl;
- cin >> b;
- cout << endl << b << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement