How do I store arrays in an STL list?

后端 未结 6 1504
感情败类
感情败类 2020-12-05 15:58

Using C++ and the STL, does anybody know how to store integer arrays as nodes in an STL list or vector? I have an unknown number of pairs of numbers that I need to store, an

6条回答
  •  旧巷少年郎
    2020-12-05 16:17

    With C++11 there is a ::std::array wrapper available which can be used with standard containers like this:

    #include 
    #include 
    #include 
    #include 
    
    int
    main()
    {
        using t_Buffer = ::std::array<::std::int32_t, 2>;
        using t_Buffers = ::std::list;
        t_Buffers buffers;
        buffers.emplace_back(t_Buffer{1, 2});
        ::std::cout << buffers.front()[0] << " " << buffers.front()[1] << ::std::endl;
        return(0);
    }
    

    Run this code online

提交回复
热议问题