Question about storing array in a std::vector in C++

前端 未结 7 1370
灰色年华
灰色年华 2021-01-12 17:07

I am unclear about the following.

First, this code compiles fine:

#include 

typedef struct{
    int x1,x2,x3,x4;
}  ints;

typedef std         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-12 17:31

    Try boost::array instead of plain arrays. It provides STL-compliant interface around fixed-size arrays, so it can be used inside STL containers. Plus, it implements boundary checking (boost::array::at).

    #include 
    #include 
    
    typedef std::vector< boost::array > vec;
    int main(){
        vec v;
        boost::array va = {0,1,2,3};
        v.push_back(va);
    }
    

提交回复
热议问题