Using STL/Boost to initialize a hard-coded setlt;vectorlt;intgt; gt;(使用 STL/Boost 来初始化一个硬编码集合lt;vectorlt;intgt;gt;)
问题描述
像这样 问题 已经问过了,我想使用 STL 初始化一个容器,其中元素以最干净的方式进行硬编码.在这种情况下,元素是一个双重嵌套的容器:
Like this question already asked, I'd like to initialize a container using STL where the elements are hard-coded in the cleanest manner possible. In this case, the elements are a doubly nested container:
set<vector<int> > A;
我想(例如)将以下值放入:
And I'd like (for example) to put the following values in:
A = [[0,0,1],[0,1,0],[1,0,0],[0,0,0]];
C++0x 很好,使用 g++ 4.4.1.STL 更可取,因为我不将 Boost 用于代码的任何其他部分(尽管我不介意使用它的示例!).
C++0x fine, using g++ 4.4.1. STL is preferable as I don't use Boost for any other parts of the code (though I wouldn't mind an example with it!).
推荐答案
这确实使用g++ 4.4.1, with -std=c++0x
This does use g++ 4.4.1, with -std=c++0x
#include <set>
#include <vector>
using namespace std;
int main()
{
set<vector<int>> A = {{0,0,1},{0,1,0},{1,0,0},{0,0,0}};
}
这篇关于使用 STL/Boost 来初始化一个硬编码集合<vector<int>>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 STL/Boost 来初始化一个硬编码集合<vector<int>>
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
