我试着用for循环做一个简单的边框。我没有得到适当的结果。具体来说,我的右边框没有显示。请帮帮忙。
const int width = 20;
const int height = 20;
void Drow()
{
system("cls"); // clear the screan
for (int i = 0; i < width; ++i)
{
cout << "*"; // upper border
}
for (int i = 0; i < height-2; i++)
{
for (int j = 0; j < width; j++)
{
if (j == 0 || j == width - 1)
{
cout << "*"; // left and right borders
}
}
cout << endl;
}
for (int i = 0; i < width; i++) // lower border
cout << "*";
}发布于 2016-05-23 23:48:40
除非我真的觉得受虐狂,否则我会做一些不同的工作。
我的直接反应是编写更多关于这个一般顺序的代码:
std::string h_border = std::string(width, '*' ) + "\n";
std::string v_border = "*" + std::string(width - 2, ' ') +"*\n";
std::cout << h_border;
for (int i = 0; i < height - 2; i++)
std::cout << v_border;
std::cout << h_border;https://stackoverflow.com/questions/37401451
复制相似问题