[Problem Call] overloading class string

Hello,
I 'm student, studying about OOP in c++.
I have problem overloading class string.

wanna output

Enter First Name : abcd
Enter Last Name : efghi
Enter you Birthday d-m-y : 01-03-1993
abcd efghi
01-03-1993


but I can't call string from class
Plz help me _ _"

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
50
51
52
53
54
55
class Person{ 
private:
    string firstName;
    string lastName;
public:
    void print() const;
    void setFirstName(string first);
    void setLastName(string last);
    string getFirstName() const;
    string getLastName() const;
    Person(string first = "", string last = "");
};

void Person :: print() const{
    cout << firstName << " " << lastName << endl;
}

void Person :: setFirstName(string first){
    firstName = first;
}

void Person :: setLastName(string last){
    lastName = last;
}

string Person :: getFirstName() const{
    return firstName;
}

string Person :: getLastName() const{
    return lastName;
}

Person :: Person(string first, string last){
    firstName = first;
    lastName = last;
}

int main(){
    string f, l;
    Person name(f, l);

    cout << "Enter your First Name : ";
    cin >> f;
    //getline(cin, f);
    
    cout << "Enter your Last Name : ";
    cin >> l;
    getline(cin, l);
    
    name(f, l).print();
    
    system("pause");
    return 0;   
}


Thank you.
Last edited on
name(f, l).print();

This makes no sense.

Did you mean name.print() ?



Also, I see that you are using f and l Person name(f, l); before you actually get any values for f and l. This is very silly. You must get values first, and then use them.
Last edited on
Yes ^^
Oh! it compiler done.
But, have not output. T^T


Enter your First Name : er
Enter your Last Name : fg
                                                                                   
Press any key to continue . . .
¿So what did you change?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main(){
    string f, l;
    Person name();

    cout << "Enter your First Name : ";
    cin >> f;
    //getline(cin, f);
    
    cout << "Enter your Last Name : ";
    cin >> l;
    //getline(cin, l);
    
    name.setFirstName(f);
    name.setLastName(l);
    name.print();
    
    //system("pause"); a good compiler will pause it automatically, don't use system, theres a topic pinned in the beginner section, take a look. http://cplusplus.com/forum/beginner/1988/
    return 0;   
}
Last edited on
It's work. ^^
Thank you so much @Zephilinox and @Moschops
any time ^^
Topic archived. No new replies allowed.