使用 STL/Boost 来初始化一个硬编码集合<vector<int>> [英] Using STL/Boost to initialize a hard-coded set<vector<int> >

查看:18
本文介绍了使用 STL/Boost 来初始化一个硬编码集合<vector<int>>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像这样 问题 已经问过了,我想使用 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 来初始化一个硬编码集合&lt;vector&lt;int&gt;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆