#include <iostream>
#include <string>
using namespace std;
class phone_number {
string phone;
public:
phone_number(const string& p) {
// validate p...
if (p.size() != 10) {
// Do something violent :)
cerr << "The phone number is incorrect." << endl;
}
phone = p;
}
friend ostream& operator<<(ostream &os, const phone_number& p);
};
ostream& operator<<(ostream &os, const phone_number& pn) {
const string &p(pn.phone);
os << "(" << p.substr(0, 3) << ")" << p.substr(3, 3) << "-" << p.substr(6);
return os;
}
int main() {
phone_number p = phone_number("6152784567");
cout << p << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIHBob25lX251bWJlciB7CnN0cmluZyBwaG9uZTsKcHVibGljOgogICAgcGhvbmVfbnVtYmVyKGNvbnN0IHN0cmluZyYgcCkgewogICAgICAgIC8vIHZhbGlkYXRlIHAuLi4KICAgICAgICBpZiAocC5zaXplKCkgIT0gMTApIHsKICAgICAgICAgICAgLy8gRG8gc29tZXRoaW5nIHZpb2xlbnQgOikKICAgICAgICAgICAgY2VyciA8PCAiVGhlIHBob25lIG51bWJlciBpcyBpbmNvcnJlY3QuIiA8PCBlbmRsOwogICAgICAgIH0KICAgICAgICBwaG9uZSA9IHA7CiAgICB9CiAgICBmcmllbmQgb3N0cmVhbSYgb3BlcmF0b3I8PChvc3RyZWFtICZvcywgY29uc3QgcGhvbmVfbnVtYmVyJiBwKTsKfTsKCm9zdHJlYW0mIG9wZXJhdG9yPDwob3N0cmVhbSAmb3MsIGNvbnN0IHBob25lX251bWJlciYgcG4pIHsKICAgIGNvbnN0IHN0cmluZyAmcChwbi5waG9uZSk7CiAgICBvcyA8PCAiKCIgPDwgcC5zdWJzdHIoMCwgMykgPDwgIikiIDw8IHAuc3Vic3RyKDMsIDMpIDw8ICItIiA8PCBwLnN1YnN0cig2KTsKICAgIHJldHVybiBvczsKfQoKCmludCBtYWluKCkgewogICAgcGhvbmVfbnVtYmVyIHAgPSBwaG9uZV9udW1iZXIoIjYxNTI3ODQ1NjciKTsKICAgIGNvdXQgPDwgcCA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0=