Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class PhoneNumber {
- public:
- friend ostream& operator<<(ostream&, const PhoneNumber&);
- friend istream& operator>>(istream&, PhoneNumber&);
- private:
- char first[4]; // 3 + '\0'
- char second[4]; // 3 + '\0'
- char third[3]; // 2 + '\0'
- char fourth[3]; // 2 + '\0'
- };
- ostream& operator<<(ostream& output, const PhoneNumber& num) {
- output << num.first << "-" << num.second << "-" << num.third << '-' << num.fourth;
- return output; //разрешить конкатенацию
- }
- istream& operator>>(istream& input, PhoneNumber& num) {
- input.getline(num.first, 4);
- cout << "num.first = " << num.first << endl;
- input.ignore();
- input.getline(num.second, 4);
- cout << "num.second = " << num.second << endl;
- input.ignore();
- input.getline(num.third, 3);
- cout << "num.third = " << num.third << endl;
- input.ignore();
- input.getline(num.fourth, 3);
- cout << "num.fourth = " << num.fourth << endl;
- return input; //разрешить конкатенацию
- }
- int main() {
- PhoneNumber phone;
- std::cout << "Enter a phone number in the form \n 123-456-78-90:\n";
- cin >> phone;
- cout << "The entered number was: " << phone << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement