Skip to content

Instantly share code, notes, and snippets.

@fpersson
Created May 12, 2013 17:30
Show Gist options
  • Save fpersson/5564326 to your computer and use it in GitHub Desktop.
Save fpersson/5564326 to your computer and use it in GitHub Desktop.
2D array in C++ 11 with std::array (note the brackets).
#include <iostream>
#include <array>
int main(){
//col, row
std::array<std::array<int, 10>, 10> mymap{{
{{1,2,3,4,5,6,7,8,9,0}},
{{1,2,3,4,5,6,7,8,9,0}},
{{1,2,3,4,5,6,7,8,9,0}},
{{1,2,3,4,5,6,7,8,9,0}},
{{1,2,3,4,5,6,7,8,9,0}},
{{1,2,3,4,5,6,7,8,9,0}},
{{1,2,3,4,5,6,7,8,9,0}},
{{1,2,3,4,5,6,7,8,9,0}},
{{1,2,3,4,5,6,7,8,9,0}},
{{1,2,3,4,5,6,7,8,9,0}}
}};
for(auto& col: mymap){
for(auto& row: col){
std::cout << row << " ";
}
std::cout << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment