fork(3) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. int main() {
  6. int rows = 10, cols = 10;
  7. std::vector<std::string> strs( rows, std::string( cols, ' ' ) );
  8. for (int x = 0; x<rows; x++)
  9. for (int y = 0; y<cols; y++)
  10. if (x == 0 || x == 9 || y == 0 || y == 9)
  11. strs[y][x] = '*'; // only issue you have to address row/column not column/row
  12.  
  13. std::string text = "foo";
  14. strs[rows/2].replace( ( cols - text.length() ) / 2, text.length(), text );
  15.  
  16. for( const auto &str : strs )
  17. std::cout << str << std::endl;
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
**********
*        *
*        *
*        *
*        *
*  foo   *
*        *
*        *
*        *
**********