I am looking to create a null terminated c-style string
where every character is -
(hyphen). I am using the following block of code:
char output_str[n + 1];
std::fill(output_str, output_str + n, '-');
output_str[n + 1] = '\0';
1) Is there a smarter C++ way to do this?
2) When I print the size of the string the output is n
, not n + 1
. Am I doing anything wrong or is null character never counted?
Edit:
Please consider this block of code instead of the one above:
char output_str[n + 1];
std::fill(output_str, output_str + n, '-');
output_str[n] = '\0';
And please ignore the question regarding size.