For loop an array in a class which isn't main

I am trying to
cout
strings from an array which I want to use as a name of a widget in gtkmm but right now I just want to output the name, on compile I get the following error

invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'std::array<std::__cxx11::basic_string<char>, 5>')

The following is part of my code
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <vector>
#include <array>

std::array<std::string, 5> games[] = {{"*WebApp_1","*WebApp_2","*WebApp_3","*WebApp_4","*WebApp_5"}};
  //std::array<std::string, games[5] = {"*WebApp_1","*WebApp_2","*WebApp_3","*WebApp_4","*WebApp_5"};
  for(const auto& game : games)
  {
    std::cout << game << std::endl;
  }
#include <string>
games is an array of size 1 containing elements of type std::array<std::string, 5>, so the type of game in the loop is const std::array<std::string, 5>& which operator<< has not been overloaded for.

If you want games to be an std::array of size 5 containing elements of type std::string you should remove the [] when declaring the variable.

 
std::array<std::string, 5> games = {"*WebApp_1","*WebApp_2","*WebApp_3","*WebApp_4","*WebApp_5"};


Hmm thanks it now works even without the #include <string>
Topic archived. No new replies allowed.