#include <iostream>
#include<string>
int main() {
const std::size_t rows = 30;
const std::size_t cols = 70;
std::string pattern[rows];
// initialize strings in pattern to be of length "cols" and all spaces:
for (std::size_t i = 0; i < rows; ++i)
pattern[i] = std::string(cols, ' ');
// top/bottom:
for (std::size_t i = 0; i < cols; ++i)
pattern[0][i] = pattern[rows - 1][i] = 'x';
// left/right:
for (std::size_t i = 1; i < rows - 1; ++i)
pattern[i][0] = pattern[i][cols - 1] = 'x';
// print the pattern out, taking advantage of the fact that each row is a string and
// cout knows how to print the whole row:
for (std::size_t row = 0; row < rows; ++row)
std::cout << pattern[row] << '\n';
std::cout << '\n';
std::cin.ignore(100, '\n');
// We want to insert "Hello" into the box without distorting the boundary:
{
std::size_t insertion_row = 5;
std::size_t insertion_col = 5;
std::string insert_me = "Hello";
for (std::size_t i = 0; i < insert_me.length(); ++i)
pattern[insertion_row][insertion_col + i] = insert_me[i];
}
// See our handiwork
for (std::size_t row = 0; row < rows; ++row)
std::cout << pattern[row] << '\n';
std::cout << '\n';
std::cin.ignore(100, '\n');
// An alternate way to insert text:
{
std::size_t insertion_row = 10;
std::size_t insertion_col = 5;
std::string insert_me = "Goodbye";
pattern[insertion_row].replace(insertion_col, insert_me.length(), insert_me);
}
// See our handiwork
for (std::size_t row = 0; row < rows; ++row)
std::cout << pattern[row] << '\n';
std::cout << '\n';
}