【发布时间】:2020-10-30 05:20:04
【问题描述】:
如何使用指针在多维数组中创建和存储字符串数据?我的尝试是:
// I declaring row 3 and column 2
string** arr = new string*[3][2]; // I am having issue in here
// I am trying to add data
arr[0] = {"first", "second"};
【问题讨论】:
-
使用
std::array<std::arrayr<std::string,2>,3> arr; -
你需要用
new string()初始化每个元素 -
网上有很多关于如何分配多维数组的例子。好的不使用指针,但我相信你也能找到。
-
@AlanBirtles,你介意给我看看这个例子吗?