What is the most efficient way to initialize a 3D vector?

后端 未结 5 1337
长情又很酷
长情又很酷 2021-02-03 11:23

I have a 3D string vector in C++:

vector>> some_vector

That I am trying is to find a fast method to all

5条回答
  •  有刺的猬
    2021-02-03 11:40

    To initialize a 3D string vector you shall initialize the vector structure for each dimension one at a time and for each index, for instance:

      vector > > myvector; //declare the 3D vector
      for(k=0; k<3; k++)
      {
        myvector.push_back(vector >()); //initialize the first index with a 2D vector
        for(i=0; i<4; i++)
        {
          myvector[k].push_back(vector()); //initialize the 2 index with a row of strings
          for(j=0; j<4; j++)
          {
             result = " whatever you want to insert in the vector element";
             myvector[k][i].push_back(result); //fulfill the last index regularly
          } 
        }
      }
    

提交回复
热议问题