How could/should I print text strings above number columns in C++?

Solution 1:

This should work:

#include <array>
#include <iostream>
#include <string>

int main(){
  std::array<std::string, 3> headlines = {"Car", "Hours", "Charge"};
  for( auto const& elem : headlines ){
    std::cout << elem << "\t";
  }
}

Solution 2:

It should be curly braces {} in the initializer, not []. And you need a comma between each element.

On the other hand, in later C++ revisions array can detect the type and number of elements, so you don't have to give that.

#include <iostream>
#include <array>
using namespace std;

int main() {

   array a = {"Car", "Hours", "Charge"};

   for (auto& item : a)
      cout<< item << endl;
}