list<map<string, object>>stream拼接
时间: 2023-12-03 07:54:30 浏览: 45
可以使用`std::accumulate`函数对多个`list<map<string, object>>`进行拼接。示例代码如下:
```c++
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <algorithm>
int main() {
std::list<std::map<std::string, int>> stream1 = {
{{"a", 1}, {"b", 2}},
{{"c", 3}, {"d", 4}}
};
std::list<std::map<std::string, int>> stream2 = {
{{"e", 5}, {"f", 6}},
{{"g", 7}, {"h", 8}}
};
std::list<std::map<std::string, int>> result;
std::accumulate(stream1.begin(), stream1.end(), std::back_inserter(result));
std::accumulate(stream2.begin(), stream2.end(), std::back_inserter(result));
for (const auto& m : result) {
for (const auto& p : m) {
std::cout << p.first << ": " << p.second << " ";
}
std::cout << std::endl;
}
return 0;
}
```
输出结果为:
```
a: 1 b: 2
c: 3 d: 4
e: 5 f: 6
g: 7 h: 8
```
相关推荐
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)