【发布时间】:2018-03-18 02:30:38
【问题描述】:
我使用了 2D 动态数组,但我不知道如何修复错误,请帮助我!我想从用户那里得到一个字符串并将其分离为一些字符串并将它们放入二维动态数组中。 它是我分配数组的代码部分。
int colCount,rowCount;
string** table = new string*[rowCount];
for(int i = 0; i < rowCount; ++i)
{
table[i] = new string[colCount];
}
【问题讨论】:
-
首先你应该使用
std::vector代替。您可以将一个向量嵌套在另一个向量中。 -
至于您的问题,请尝试创建Minimal, Complete, and Verifiable Example 并告诉我们。例如,您需要告诉我们
colCount和rowCount的值,并且最好告诉我们您是如何初始化它们的。请花点时间read about how to ask good questions。
标签: c++ arrays memory-management dynamic-memory-allocation bad-alloc