title: How do I print out the contents of a vector?
body: <p>How do I print out the contents of a <code>std::vector</code> to the screen?</p>
  <hr />
  <p>A solution that implements the following <code>operator&lt;&lt;</code> would be nice as well:</p>
  <pre><code>template&lt;container C, class T, String delim = &quot;, &quot;, String open = &quot;[&quot;, String close = &quot;]&quot;&gt;
  std::ostream &amp; operator&lt;&lt;(std::ostream &amp; o, const C&lt;T&gt; &amp; x)
  {
    // ... What can I write here?
  }
  </code></pre>
  <hr />
  <p>Here is what I have so far, without a separate function:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;cmath&gt;
  #include &lt;vector&gt;
  #include &lt;sstream&gt;
  #include &lt;cstdio&gt;
  using namespace std;
  
  int main()
  {
      ifstream file(&quot;maze.txt&quot;);
      if (file) {
          vector&lt;char&gt; vec(istreambuf_iterator&lt;char&gt;(file), (istreambuf_iterator&lt;char&gt;()));
          vector&lt;char&gt; path;
          int x = 17;
          char entrance = vec.at(16);
          char firstsquare = vec.at(x);
          if (entrance == 'S') { 
              path.push_back(entrance); 
          }
          for (x = 17; isalpha(firstsquare); x++) {
              path.push_back(firstsquare);
          }
          for (int i = 0; i &lt; path.size(); i++) {
              cout &lt;&lt; path[i] &lt;&lt; &quot; &quot;;
          }
          cout &lt;&lt; endl;
          return 0;
      }
  }
  </code></pre>