c++ - Copy a vector to an array? -


i copied 2dim array 2dim vector , did modifications on it, want know how can copy 2dim vector 2dim array?(i did below:)

copy 2dim array 2dim vector:

vector< vector<int>> path2;  vector<int> temp; // simplicity  (int x = 0; x <= 1; x++) {temp.clear();     (int y = 0; y < 4; y++)     {         temp.push_back(path1[x][y]);     }     path2.push_back(temp);  } 

out put:

path2[0][6,0,2,6] path2[1][6,1,3,6] 

copy 2dim vector 2dim array

int arr [4][10] ;  copy(path3.begin(), path3.end(), arr); 

print arr

 (int i=0;i< ???? ;i++)// how define size of vector first dimention 2 ( aware size() 1 dim vector, 2dim vector ...... ??????????      for(int j=0;j<?????; j++) //same prolem above          cout<<endl<<arr[i][j]; 

the problem not sure copy part , and dont know how define size of each size of vector?

you of these iterate on vector of vector:

//works c++11 std::vector<std::vector<int>> vec; for(auto &i : vec)    for(auto &j : i)       std::cout << j << std::endl;  //works c++11 (auto iter = vec.cbegin(); iter != vec.cend(); ++iter)     for(auto sub_iter = iter->cbegin(); sub_iter != iter->cend(); ++sub_iter)        std::cout << *sub_iter << std::endl;  //works c++03 , c++11 typedef std::vector<std::vector<int> >::iterator iter; typedef std::vector<int>::iterator sub_iter; (iter iter = vec.begin(); iter != vec.end(); ++iter)     for(sub_iter sub_iter = iter->begin(); sub_iter != iter->end(); ++sub_iter)        std::cout << *sub_iter << std::endl;   //works c++03 , c++11 for(int = 0; i<vec.size(); ++i)     for(int j = 0; j < vec[i].size(); ++j)        std::cout << vec[i][j] << std::endl; 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -