initializing char array with spaces

c, c++, char, string

Solution

std::string foo(num_space_req,' ');

Problem

I want a 20 character NULL('\0') terminating string filled with white spaces. Currently I am doing it in following way ``` char foo[20]; for (i = 0; i < num_space_req; i++) //num_space_req < 20 { foo[i] = ' '; } foo[num_space_req] = '\0'; ``` Is there a better way for above?

Original source