【发布时间】:2017-02-25 09:13:47
【问题描述】:
我对 C++ 还有些陌生,在使用 cout 方面需要一些帮助。
int main()
{
char letterGrades[25] = { 'a', 'b', 'c', 'd', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', };
for (int i = 0; i < 25; i++)
{
printf("[%d] --> %c", i, letterGrades[i]);
if (i == 3) // how can I print \n when i == 7 , 11 , 15 , 19....
{
printf("\n");
}
}
}
这就是我想要做的,而且效果很好。但是,我不知道如何使用 cout 编写此代码。
另外,我会以 4 in a row 表格格式打印结果。 所以结果看起来像这样
[0] --> A [1] --> A [2] --> A [3] --> A
[4] --> A [5] --> A [6] --> A [7] --> A
[8] --> A [9] --> A [10] --> A [11] --> A
【问题讨论】:
-
cout << i << " --> " << letterGrades[i]; -
对于换行符,你可以:
cout << endl;,都假设你是using namespace std