如何将类型QList<int> IpcInfo_IpcID链表里面的值 存进 std::list<int> mylist。?
时间: 2023-12-24 21:02:06 浏览: 106
您可以使用STL算法中的std::copy函数将QList<int>转换为std::list<int>。以下是一个示例代码:
```cpp
#include <QList>
#include <list>
#include <algorithm>
int main()
{
QList<int> ipcInfo_IpcID = {1, 2, 3, 4, 5};
std::list<int> mylist;
std::copy(ipcInfo_IpcID.begin(), ipcInfo_IpcID.end(), std::back_inserter(mylist));
// 现在mylist包含了ipcInfo_IpcID中的所有值
return 0;
}
```
在此示例中,我们首先声明了一个QList<int>,并初始化了一些值。然后我们声明了一个std::list<int>,来存储我们想要转换的值。
我们使用std::copy函数,将QList<int>的值复制到std::list<int>中。我们将QList<int>的begin()和end()迭代器作为std::copy函数的第二个和第三个参数,并使用std::back_inserter函数作为std::copy函数的第四个参数。
std::back_inserter函数是一个方便的函数对象,它会在std::list<int>的末尾插入新值。这确保了我们可以正确地将QList<int>的值复制到std::list<int>中。
最后,我们可以检查std::list<int>中的值,以确保它们已正确复制。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)