array4.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* example for using class array<>
  2. * (C) Copyright Nicolai M. Josuttis 2001.
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <algorithm>
  8. #include <functional>
  9. #include <string>
  10. #include <iostream>
  11. #include <boost/array.hpp>
  12. int main()
  13. {
  14. // array of arrays of seasons
  15. boost::array<boost::array<std::string,4>,2> seasons_i18n = {
  16. { { { "spring", "summer", "autumn", "winter", } },
  17. { { "Fruehling", "Sommer", "Herbst", "Winter" } }
  18. }
  19. };
  20. // for any array of seasons print seasons
  21. for (unsigned i=0; i<seasons_i18n.size(); ++i) {
  22. boost::array<std::string,4> seasons = seasons_i18n[i];
  23. for (unsigned j=0; j<seasons.size(); ++j) {
  24. std::cout << seasons[j] << " ";
  25. }
  26. std::cout << std::endl;
  27. }
  28. // print first element of first array
  29. std::cout << "first element of first array: "
  30. << seasons_i18n[0][0] << std::endl;
  31. // print last element of last array
  32. std::cout << "last element of last array: "
  33. << seasons_i18n[seasons_i18n.size()-1][seasons_i18n[0].size()-1]
  34. << std::endl;
  35. return 0; // makes Visual-C++ compiler happy
  36. }