Initialization of a vector of vectors?

后端 未结 4 1948
孤街浪徒
孤街浪徒 2020-12-15 06:17

Is there a way to initialize a vector of vectors in the same ,quick, manner as you initialize a matrix?

typedef int type;

type matrix[2][2]=
{
{1,0},{0,1}
         


        
4条回答
  •  悲哀的现实
    2020-12-15 07:07

    In C++0x, I think you can use the same syntax as for your matrix.

    In C++03, you have to write some tedious code to populate it. Boost.Assign might be able to simplify it somewhat, using something like the following untested code:

    #include 
    
    vector > v;
    v += list_of(1)(0), list_of(0)(1);
    

    or even

    vector > v = list_of(list_of(1)(0))(list_of(0)(1));
    

提交回复
热议问题