C++代码的输出问题。
目前我想要用c++代码输出以下图案(那个符号代表空格)
我自己写的代码输出
我不知道应该如何修改
#include <iostream>
#include <string>
void under(int s) {
std::string top_bottom_row(2*s, '*');
std::string bottom_row(s, '*');
std::cout << top_bottom_row << std::endl;
int i;
for ( i = 1; i < s - 1; ++i) {
std::string middle_row = "*" + std::string(2*s - 2*i, ' ') + "*";
std::string spaces(i-1, ' ');
std::cout << spaces << middle_row << std::endl;
}
std::string spaces(i, ' ');
std::cout << spaces << bottom_row << std::endl;
}
int main() {
under(4);
under(6);
under(10);
return 0;
}