int a[5] = { 1,2,3,4,5 };
#迭代
for (int i : a)
{
cout << i << endl;
}
#普通for循环
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
{
cout << a[i] << endl;
}
int a[5] = { 1,2,3,4,5 };
#迭代
for (int i : a)
{
cout << i << endl;
}
#普通for循环
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
{
cout << a[i] << endl;
}
本文标题:c++的两种循环遍历
本文链接:https://www.haomeiwen.com/subject/mzzrlqtx.html
网友评论