【发布时间】:2020-10-14 22:07:18
【问题描述】:
std::vector<std::tuple<PCWSTR, PCWSTR,PCWSTR> > tempVector;
tempVector.push_back({ L"temp", L"temp1", L"temp2" });
tempVector.push_back({ L"data", L"data1", L"data2" });
const ULONG fieldCount = tempVector.size();
PCWSTR fieldNames = new PCWSTR[fieldCount];
PCWSTR fieldValues = new PCWSTR[fieldCount];
PCWSTR fieldSize = new PCWSTR[fieldCount];
int index=0;
for (std::vector<std::tuple<PCWSTR, PCWSTR, PCWSTR>>::iterator it = tempVector.begin(); it != tempVector.end(); ++it) {
fieldNames[index] = it->_Myfirst;// I know this is incorrect code, how do I fetch the first value here..
fieldValues[index] = it->second;
fieldSize[index] = it->third;
index++;
}
有没有其他方法可以迭代这些元组值并将其填充到数组中...
【问题讨论】:
-
std::vector<std::tuple<PCWSTR, PCWSTR, PCWSTR>>::iterator和“最佳案例使用auto”的每周奖授予... -
A range-based
forloop 比手动使用迭代器要好 -
如何使用自动,我确实看到了几个例子,但不太确定......
-
@RemyLebeau 你能给我一个链接吗.. 不知道如何使用它..
-
@ccoding 只需将那个大的长类型名称换成
auto就可以了。
标签: c++ vector iterator tuples