2012-05-01 252 views

回答

3

数组是在C和C++不可改变。你不能重新分配他们。

您可以使用memcpy

memcpy(arrtemp, words[i], 16 * sizeof(int)); 

此副本16 * sizeof(int)字节从words[i]arrtemp

+2

这是一个奇怪的用字不可改变的。我只听说过不可改变的词用来描述内容不能改变的对象。 –

5

使用std::copy

int words[40][16]; //Be sure to initialise words and i at some point 
int arrtemp[16]; 
//If you don't have std::begin and std::end, 
//use boost::begin and boost::end (from Boost.Range) or 
//std::copy(words[i] + 0, words[i] + 16, arrtemp + 0) instead. 
std::copy(std::begin(words[i]), std::end(words[i]), std::begin(arrtemp)); 
+0

这是否工作在C++ 11之前? –

+0

@LuchianGrigore,我认为它没有。 – chris

+2

'的std ::开始()'和'的std ::端()'其中添加在C++ 11,但可以使用'的std ::拷贝(字[0],词语[0] + 16,arrtemp) ;'在pre C++ 11中。 – hmjd