How to assign a const char* to char*

I'm writing a code in which I have to pass a const char* into the class overloaded constructor and to assign this const char* to the char* variable which is a private member of the class. I'm doing this type of code but doesn't working giving an error that a const char* cannot be assigned to char* type.
Here is the code:
1
2
3
4
5
  Player::Player(const char* chr,int iNum)
{
	name=chr;

}

you shouldn't assign the pointer. Instead copy the content. You need of course appropriate memory space to do so

The best would be to use std::string. if you don't want to do that you may use strcpy()
Topic archived. No new replies allowed.