如何将1 d char数组分配给没有循环的2 d数组。 [英] how to assign 1 d char array to 2 d array without loop.

查看:58
本文介绍了如何将1 d char数组分配给没有循环的2 d数组。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char可能[50] [20];

char数据[20];

//初始化数组

/ *:

:一些代码



:* /



可能[0 ] =数据;

//错误

//无效的数组赋值

//我怎么能这样做然后请任何人...请帮助help

char possible[50][20];
char data[20];
//initialise the array
/*:
:some code
:
:*/

possible[0]=data;
//error
//invalid array assignment
//how can i do it then pls anyone ...pls help

推荐答案

您需要将数据的内容复制到可能[0] 。您不能只分配引用。
You need to copy the contents of data to possible[0]. You cannot just assign a reference.


在C ++中,您无法直接将数组复制到另一个数组中。你必须用循环元素逐个元素复制。



我只知道家庭的语言 xBase (很老)这些语言如 Clipper Visual Fox Pro 将2d数组视为列表列表,列表的处理方式与简单值完全相同,使您的写作合法。
In C++, you can't copy an array into another array directly. you must copy element by element with a loop.

I know only languages of the familly xBase (very old languages) to be able to do it.
These languages like Clipper or Visual Fox Pro consider a 2d array as a list of lists and a list is handled exactly like a simple value, making your writing legal.


仅提示!



文字没有复制运算符。因此,您应该为元素使用memcpy或循环。
Only a hint!

There is no copy operator for literals. Therefore you should use memcpy or a loop for the elements.


这篇关于如何将1 d char数组分配给没有循环的2 d数组。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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