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= newchar[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.....
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.