指向2d数组的指针 [英] pointer to 2d array

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

问题描述

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


int map [] [];

map = new int [16 ] [16];

map [5] [5] = 3;

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


提前感谢。

解决方案

Mark写道:

放得最多简单地说,什么是相当于这个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




Mark写道:

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

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

感谢
你可以使用vector来动态模拟它。

#include< iostream>

#使用namspace std包含< vector>

;

.....


vector< vector< int> > MyMap(16,vector< int>(16));

MyMap [5] [5] = 3;

cout<< MyMap [5] [5]<< endl;


Mark写道:

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

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

提前谢谢。




就个人而言,我会


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.

解决方案

Mark wrote:

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]);



# include <iostream>

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



Mark wrote:

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.



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;


Mark wrote:

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.



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数组的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆