function set..dont now how to do it???

hi, im stucked in doing the function set of my class which takes to daynamic arrays as data member ...now if the client prog wants to set the 2 data members
which are of type pointer to char array, he will insert a string how to do this
here are my codes if any one can help me.
class:
1
2
3
4
5
6
class employee
{
private:
	char *firstName;
	char *lastName;
...};

definition of the set first name:
1
2
3
4
5
6
7
void employee::setFname(string Fname)
{
	firstName= new char[strlen(Fname)+1];//strlen will give us the lenght of the string without the null charectar so +1
	//copy the string firstN to firstName
	strcpy(firstName,Fname);
    
}

it gives me an erorr of cannot convert string to char.....

what should i do?
thanks in advance.
You define string Fname as a variable of string data-type. Then you define char *firstName as char* data-type. With different data-types of cuz you cannot use strcpy.

First ask yourself. You want to play with char * or string ? When you decide on which data-type then we can use the appropriate functions that act on them.

Btw, strcpy is acting on char * not C++ string.
i should play with char* ,and im confused because the input name will be
string ?!!!
If you want to play with char*, C++ string has a method called c_str() which return the char* of the string.

E.g
firstName= new char[strlen(Fname.c_str())+1];
strcpy(firstName,Fname.c_str());
ok, thanks i will try it ^__^
Topic archived. No new replies allowed.