#include<iostream>
#include<iomanip>
using namespace std;
void main()
{
int a[3][4] = { 1,2,3,4,5,6,7,8,9,10,11,12 };
for (int i = 0;i < 3;i++)
{
for (int j = 0;j < 4;j++)
std::cout << setw(4)<<a[i][j] << " ";
std::cout << std::endl;
}
std::cin.get();
}
C++二维数组输出
本文展示了一个使用C++语言的程序示例,该程序通过二维数组a[3][4]来演示如何使用for循环和标准输出流(std::cout)进行格式化输出。程序首先定义并初始化了数组,然后通过双重for循环遍历数组的每个元素,并使用setw(4)函数设置输出宽度为4,确保输出格式整齐。最后,程序通过std::cin.get()暂停执行,以便查看输出结果。
7万+

被折叠的 条评论
为什么被折叠?



