Q:

C++ Make a Char Array have a Value of the string

For my program, I have a highscore section.  I get the input with a string, but how can I now make the string equal into a char array?  FYI: The string playersName will already be filled out with a name.  Here is my code:
class Highscore
{
    public:
        char name[10];
        ...[Code]...
}

...[Code]...
// Declare variables *The playersName will be filled out already*
string playersName = "";
...[Code]...

// How can I get the data[playerScore].name equal my playersName string? 
cin.get (data[playerScore].name, 9);
// I know cin.get will be not in the code since I already get the players name with the string

A:

You can use std::string::copy member function, like
// length of the destination buffer so we won't overflow
size_t length = sizeof data[playerScore].name; 

// copy the string content to the char buffer
playersName.copy(data[playerScore].name, length);

// add the `'\0'` at the end
data[playerScore].name[length] = '\0';

