I’m getting some errors when using strcpy_s and can’t figure out what I’m doing wrong.
The code:
Player.hpp:
string name;
Player(string);
Player.cpp:
Player::Player(string newName)
{
strcpy_s(name, name.size(), newName);//error is here
health = 20;
}
The errors:
- Too many arguments in function call
- No instance of overloaded function ‘strcpy_s’ matches the argument list
You cannot use
strcpy_sto copystd::string. Actually, you just need to do:Even better, you could use a constructor initialization list:
As a reference, here you have a detailed description of std::string class.