(C++) StdArrayExample3

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) StdArrayExample3

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • STL STL: GNU ISO C++ Library, version 4.9.2

 

 

 

 

 

Qt project file: ./CppStdArrayExample3/CppStdArrayExample3.pro

 


include(../../ConsoleApplication.pri) #Or use the code below # QT += core # QT += gui # greaterThan(QT_MAJOR_VERSION, 4): QT += widgets # CONFIG   += console # CONFIG   -= app_bundle # TEMPLATE = app # CONFIG(release, debug|release) { #   DEFINES += NDEBUG NTRACE_BILDERBIKKEL # } # QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++ # unix { #   QMAKE_CXXFLAGS += -Werror # } SOURCES += main.cpp

 

 

 

 

 

./CppStdArrayExample3/main.cpp

 


#include <array> #include <cassert> #include <iostream> int main() {   //Create a Y-X ordered 2D std::array   static const int n_rows = 2;   static const int n_cols = 3;   std::array<std::array<int,n_cols>,n_rows> v;   //Must be initialized   for (int y=0; y!=n_rows; ++y)   {     for (int x=0; x!=n_cols; ++x)     {       //Use std::array<T,U>::at to check for range       v[y][x] = x + (y * n_cols);       assert(v.at(y).at(x) >= 0);     }   }   for (const auto row: v)   {     for (const auto cell: row)     {       std::cout << cell << " ";     }     std::cout << '\n';   } } /* 0 1 2 3 4 5 Press <RETURN> to close this window... */