本文介绍了二维数组值C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要声明一个二维数组并赋值给它,不运行一个for循环。

我想我可以用下面的想法

  int数组[5] = {1,2,3,4,5};

工作正常初始化二维数组为好。但很显然,我的编译器不喜欢这样。

  / *
 1 8 12 20 25
 5 9 13 24 26
* /#包括LT&;&iostream.h时GT;诠释的main()
{
    INT ARR [2] [5] = {0}; //这实际上一切都初始化为0。
    改编[1] [] = {1,8,12,20,25}; // 11号线
    ARR [2] [] = {5,9,13,24,26};
    返回0;
}

Please help as to what is the right way to initialize the 2d array with my set of values.

解决方案

Like this:

int main()
{
    int arr[2][5] =
    {
        {1,8,12,20,25},
        {5,9,13,24,26}
    };
}

This should be covered by your C++ textbook: which one are you using?

Anyway, better, consider using std::vector or some ready-made matrix class e.g. from Boost.

这篇关于二维数组值C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 17:16
查看更多