【发布时间】:2014-01-29 03:34:00
【问题描述】:
我已经动态分配了一个 3D 数组。然后我将字符串分配到数组中。 3D 阵列打印效果很好。但我似乎找不到将它传递给函数的方法。我尝试了许多将数组传递给函数的变体。以下是我的代码,非常感谢您的帮助。
//dynamically allocate 3d array
string *** array3D;
array3D = new string**[rows];
for(int i = 0; i < rows; i++)
{
array3D[i] = new string*[columns];
for(int j=0; j < columns;j++)
{
array3D[i][j] = new string[pages];
}
}
//put strings from file into array
for(int k = 0; k < pages; k++)
{
for(int i = 0; i < rows; i++)
{
for(int j=0; j < columns;j++)
{
puzzleFile >> array3D[i][j][k];
}
}
}
// Call function
find(array3D);
// The couts are simply to verify the array passed in successfully
void find(string ***&array)
{
cout << "in function array[0][0][0]" << array[0][0][0] << endl;
cout << "array[1][0][2]" << array[1][0][2] << endl;
cout << "array[1][0][2]" << array[0][2][1] << endl;
return;
}
【问题讨论】:
-
什么问题?我在这里没有看到任何问题。你已经传递给函数了。
-
我得到一个错误,如果我复制并粘贴错误会有帮助
-
是的.. 在此处添加您的错误。
-
错误状态:无法声明指向 'std::string& {aka truct std::basic_string
&} 的指针 -
如果这是 o 任何帮助::: 候选是:模板
typename __gnu_cxx::__enable_if<:__is_char>::__value, std::istreambuf_iterator<_chart2 std ::char_traits> > >::__type std::find(std::istreambuf_iterator<_chart2 std::char_traits> >, std::istreambuf_iterator<_chart2 std::char_traits> >, const _CharT2& ) /usr/include/c++/4.6/bits/stl_algo.h:4394:5: 注意:模板 _IIter std::find(_IIter, _IIter, const _Tp&)
标签: c++ arrays function dynamic-memory-allocation