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>>
基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01