How to copy a value

Suppose I've entered string

1
2
3
4
char username[20];
std::string user_name;
std::cout << "Username: ";
std::getline(std::cin, user_name);


I to copy the value from user_name to username.
Last edited on
1
2
std::strncpy(username, user_name.c_str(), 20);
username[19] = '\0'; //Safeguard 
Last edited on
Topic archived. No new replies allowed.