title: Overloading output operator for arrays
body: <p>According to <a href="https://stackoverflow.com/a/7439211/1925388">this answer</a>, the correct way to overload output operator <code>&lt;&lt;</code> for C-style arrays is this -:  </p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  template &lt;size_t arrSize&gt;
  std::ostream&amp; operator&lt;&lt;( std::ostream&amp; out, const char( &amp;arr )[arrSize] )
  {
      return out &lt;&lt; static_cast&lt;const char*&gt;( arr ); // use the original version
  }
  
  // Print an array
  template&lt;typename T1, size_t arrSize&gt;
  std::ostream&amp; operator &lt;&lt;( std::ostream&amp; out, const T1( &amp; arr )[arrSize] )
  {
      out &lt;&lt; "[";
      if ( arrSize )
      {
          const char* separator = "";
          for ( const auto&amp; element : arr )
          {
              out &lt;&lt; separator;
              out &lt;&lt; element;
              separator = ", ";
          }
      }
      out &lt;&lt; "]";
      return out;
  }
  
  int main()
  {
      int arr[] = {1, 2, 3};
      cout &lt;&lt; arr;
  }
  </code></pre>
  
  <p>But I am still getting the compiler error  </p>
  
  <pre><code>error: ambiguous overload for 'operator&lt;&lt;' (operand types are 'std::ostream {aka std::basic_ostream&lt;char&gt;}' and 'const char [2]')  
  </code></pre>
  
  <p>for the <code>out &lt;&lt; "[";</code> and <code>out &lt;&lt; "]";</code> statements.  </p>
  
  <p>What is the correct way of doing this ?</p>