指向2d数组的指针

指向2d数组的指针

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

问题描述

最简单的说,什么是相当于这个java代码的c ++?


int map [] [];

map = new int [16 ] [16];

map [5] [5] = 3;

System.out.println(map [5] [5]);


提前感谢。

解决方案




#include< iostream>


int main()

{

int map [16] [16] = {0};

map [5] [5] = 3;

std :: cout<< map [5] [5]<< " \ n";

}

Jonathan






就个人而言,我会


vector<矢量<诠释> > map;

map.resize(16);

for(int i = 0; i< 16; ++ i)

map [i] .resize(16);

map [5] [5] = 3;

cout<< map [5] [5]<<结束;


但这可能不是最简单的因为我正在使用STL。


-JJ


put most simply, what is the c++ equivalent to this java code?

int map[][];
map = new int[16][16];
map[5][5] = 3;
System.out.println(map[5][5]);

thanks in advance.

解决方案



# include <iostream>

int main()
{
int map[16][16] = {0};
map[5][5] = 3;
std::cout << map[5][5] << "\n";
}
Jonathan




You can use vector to simulate this dynamically.
#include <iostream>
#include <vector>
using namspace std;
.....

vector<vector<int> > MyMap(16, vector<int>(16));
MyMap[5][5] = 3;
cout << MyMap[5][5] << endl;




Personally, I would

vector< vector<int> > map;
map.resize( 16 );
for ( int i = 0; i < 16; ++i )
map[i].resize( 16 );
map[5][5] = 3;
cout << map[5][5] << endl;

But that might not be "most simply" since I''m using STL.

-JJ


这篇关于指向2d数组的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:45