struct ceshi
{
int frist = 0;
int second = 0;
};
int main(int argc, char *argv[])
{
QList<ceshi> list;
ceshi c1;
c1.frist = 1;
c1.second = 2;
ceshi c2;
c2.frist = 3;
c2.second = 4;
list << c1 << c2;
std::list<ceshi> list2;
list2.resize(list.size());
auto ret = std::copy(std::begin(list),std::end(list),std::begin(list2));
for (auto it = list2.begin();it != list2.end();++it)
{
qDebug()<<it->frist<<it->second;
}
}
其中:
list2.resize(list.size());
将两个容器的大小设为相同是必不可少的一步。
auto ret = std::copy(std::begin(list),std::end(list),std::begin(list2));
迭代器(指针)ret指向拷贝list2的尾元素之后的位置。
auto ret = std::copy(std::begin(list),std::end(list),std::begin(list2));
--ret;
qDebug()<<ret->frist<<ret->second;