First, to declare a simple string, you do not need pointers:
std::string str;
To fill a string with content of a given size, you can use the constructor:
std::string str( width, ' ' );
To fill in the lines, you can use the replace method:
str.replace( pos, length, length , '#' );
You should do convenient checks. You can also use iterators directly.
In general, for containers (a string is a container of characters), you can also use the std :: fill algorithm
std::fill( str.begin()+pos, str.begin()+pos+length, '#' );
Nikko
source share