前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++遍历二维数组的四种方法

C++遍历二维数组的四种方法

作者头像
用户1680321
发布2022-03-10 16:22:32
9060
发布2022-03-10 16:22:32
举报
文章被收录于专栏:yw的数据分析yw的数据分析
代码语言:javascript
复制
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::begin;
using std::end;
int main()
{
int ia[3][4];
size_t cnt=0;
for (auto &row:ia){
    for (auto &col:row){
        col=cnt;
        ++cnt;
    }
}

constexpr size_t rowCnt=3,colCnt=4;
for (size_t i=0;i != rowCnt; ++i){
    for (size_t j=0;j != colCnt;++j){
        cout << ia[i][j] <<endl;
    }
}
for (int(*p)[4] = ia;p != ia+3;p++){
    for (int *q = *p;q != *p+4;q++){
        cout << *q << endl;
    }
}
for (int(*p)[4] = begin(ia);p != end(ia);p++){
    for (int *q = begin(*p);q != end(*p); q++){
        cout << *q <<endl;
    }
}
for (int (&p)[4]:ia){
    for (int &q:p){
        cout << q << endl;
    }
}
return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-03-01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档