need help with operator friend functions

#include<iostream>
#include<iomanip>
using namespace std;

class PhoneNumber
{
friend ostream &operator<<(ostream &, const PhoneNumber &);
friend istream &operator>>(istream &, PhoneNumber &);
public:
PhoneNumber()
{

}
private:
string areaCode;
string exchange;
string line;
};

ostream &operator<<(ostream &outPut, const PhoneNumber &number)
{
outPut << "(" <<number.areaCode << ") "
<< number.exchange << "-" <<number.line;
return outPut;
}

istream &operator>>(istream &input, PhoneNumber &number)
{
input.ignore();
input >> setw(3)>>number.areaCode;
input.ignore(2);
input >> setw(3) >> number.exchange;
input.ignore();
input>> setw(4)>> number.line;
return input;

}

int mina()
{
PhoneNumber Phone;
cout<<"Enter Phone Number"<<endl;
cin >> Phone;
cout<<"The Phone Number entered was"<<endl;
cout<<Phone<<endl;

}

Why wont this compile?!
Because there is no function main() in your code.

And what is this function???
1
2
3
4
5
6
7
8
int mina()
{
    PhoneNumber Phone;
    cout<<"Enter Phone Number"<<endl;
    cin >> Phone;
    cout<<"The Phone Number entered was"<<endl;
    cout<<Phone<<endl;
}
Make sure that you put your code into tags so that it's easier for others to read and review so that they can give you input.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#include<iostream>
#include<iomanip>
using namespace std;

class PhoneNumber
{
friend ostream &operator<<(ostream &, const PhoneNumber &);
friend istream &operator>>(istream &, PhoneNumber &);
public:
PhoneNumber()
{

}
private:
string areaCode;
string exchange;
string line;
};

ostream &operator<<(ostream &outPut, const PhoneNumber &number)
{
outPut << "(" <<number.areaCode << ") "
<< number.exchange << "-" <<number.line;
return outPut;
}

istream &operator>>(istream &input, PhoneNumber &number)
{
input.ignore();
input >> setw(3)>>number.areaCode;
input.ignore(2);
input >> setw(3) >> number.exchange;
input.ignore();
input>> setw(4)>> number.line;
return input;

}

int mina()
{
PhoneNumber Phone;
cout<<"Enter Phone Number"<<endl;
cin >> Phone;
cout<<"The Phone Number entered was"<<endl;
cout<<Phone<<endl;

}
Just a few things that I am seeing from glancing at it on line 40, it should be int main(){

Just a simple typing error

Then you need return 0; in your main.
Omg! thank you all! I'm blind!
And 1 last question, how would you guys go about returning an array from a class member?
Topic archived. No new replies allowed.