2012-05-01 249 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