Problem with string in header file.

Hello,
I'm having problems with making a class which includes one data type of string. However if i change it from string to character it works fine.Here's the code:
Header file:
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
#include<string>

class employe {
private:
	std::string name;
	int age;
	int empno;
	int fonno;
	int salary;
public:
	employe();
	employe(string n, int a, int e, int f, int s);
	employe(const employe&emp);
	void setname(string n);
	void setage(int a);
	void setempno(int e);
	void setfonno(int f);
	void setsalary(int s);
	string getname();
	int getage();
	int getempno();
	int getfonno();
	int getsalary();
	void displayemployeinfo();
};


Definition:
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
#include<string>
#include"employe.h"
using namespace std;
employe::employe()
{
	name = "";
	age = 0;
	empno = 0;
	fonno = 0;
	salary = 0;
}
employe::employe(string n, int a, int e, int f, int s)
{
	name = n;
	age = a;
	empno = e;
	fonno = f;
	salary = s;
}
employe::employe(const employe&emp)
{
	name = emp.name;
	age = emp.age;
	empno = emp.empno;
	fonno = emp.fonno;
	salary = emp.salary;
}
void employe::setname(string na)
{
	name = na;
}
void employe::setage(int a)
{
	age = a;
}
void employe::setempno(int e)
{
	empno = e;
}
void employe::setfonno(int f)
{
	fonno = f;
}
void employe::setsalary(int s)
{
	salary = s;
}
string employe::getname()
{
	return name;
}
int employe::getage()
{
	return age;
}
int employe::getempno()
{
	return empno;
}
int employe::getfonno()
{
	return fonno;
}
int employe::getsalary()
{
	return salary;
}
void employe::displayemployeinfo()
{
	cout << " NAME OF THE EMPLOYE IS = " << name << endl;
	cout << " AGE OF THE EMPLOYE IS = " << age << endl;
	cout << " EMPLOYEE NUMBER OF THE EMPLOYE IS = " << empno << endl;
	cout << " PHONE NUMBER OF THE EMPLOYE IS = " << fonno << endl;
	cout << " SALARY OF THE EMPLOYE IS = " << salary << endl << endl << endl;
}


Driver:
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
#include<iostream>
#include"employe.h"
#include <string>
using namespace std;
void main()
{
	employe emp[2];
	{
		emp[0].setname("Daniel");
		emp[0].setage(21);
		emp[0].setempno(21314);
		emp[0].setfonno(00000000000);
		emp[0].setsalary(1500);
	}
	{
		emp[1].setname("Maxwell");
		emp[1].setage(19);
		emp[1].setempno(41321);
		emp[1].setfonno(11111111111);
		emp[1].setsalary(2300);
	}
	for (int i = 0; i < 2; i++)
	{
		emp[i].displayemployeinfo();
	}
	employe();
	employe emp1(emp[0]);

}

Sorry if I made a simple mistake I'm still a beginner.
Last edited on
Don't forgot std:: in front of string.

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
#include<string>

class employe {
private:
	std::string name;
	int age;
	int empno;
	int fonno;
	int salary;
public:
	employe();
	employe(std::string n, int a, int e, int f, int s);
	employe(const employe&emp);
	void setname(std::string n);
	void setage(int a);
	void setempno(int e);
	void setfonno(int f);
	void setsalary(int s);
	std::string getname();
	int getage();
	int getempno();
	int getfonno();
	int getsalary();
	void displayemployeinfo();
};
Thank you for your help.
Topic archived. No new replies allowed.