我想知道如何简化和概括字符串向量向量的初始化:
vector<vector<wstring>> vvValues;
const wchar_t *row1[] = { L"R1C1_variablesize"};
const wchar_t *row2[] = { L"R2C1_vsize" , L"R2C2_varsize", L"R2C3_variabsize"};
const wchar_t *row3[] = { L"R3C1_variablsize", L"R3C2_vasize"};
vvValues.push_back (vector<wstring> (row1, end(vrow1)));
vvValues.push_back (vector<wstring> (row2, end(row2)));
vvValues.push_back (vector<wstring> (row3, end(row3)));
我尝试使用临时数组
const wchar_t **rows[] = {row1, row2, row3);
使用迭代器,我成功测试
for (auto it = begin(rows); it!= end(rows); ++it)
vvValues.push_back (vector<std::wstring> (*it, *it + 0));
在 row1、row2、row3 上使用 count()、sizeof() 或 end(),行按预期工作。
->但我不知道如何获取每行元素的数量
IE
sizeof(rows[0]) -> 4
sizeof(rows[1]) -> 12
sizeof(rows[2]) -> 8
甚至更好
sizeof(it) -> 4, 12, 8 on each iteration.
非常感谢
你把我带到了这个 工作解决方案
vector<vector<wstring>> vvValues;
// First string -> # of strings excluding index
const wchar_t *row1[] = { L"1", L"R1C1_variablesize"};
const wchar_t *row2[] = { L"3", L"R2C1_vsize" , L"R2C2_varsize", L"R2C3_variabsize"};
const wchar_t *row3[] = { L"2", L"R3C1_variablsize", L"R3C2_vasize"};
const wchar_t **rows[] = {row1, row2, row3);
for (unsigned long it = 0; it < sizeof(rows)/sizeof(wchar_t *); ++it)
vvValues.push_back (vector<std::wstring> (rows[it] + 1,
rows[it] + 1 + wcstoul(rows[it][0], NULL, 0)));