Friday, September 1, 2017

C++11: Containers: array

An array container was added that does not have the overhead of a vector container. Here is an example:

#include <array>
#include <iostream>

int main()
{
  std::array<int, 7> a = {0, 1};
  
  a[6] = 6;

  std::cout << sizeof(a) << " " << a[0] << " "
                                << a[1] << " "
                                << a[6] << std::endl;
  return 0;
}
// Output: 28 0 1 6
Reference: https://isocpp.org/wiki/faq/cpp11-library-stl#cpp11-containers

No comments:

Post a Comment