title: C++ range based forloop traversing a vector but cout only prints first item in the loop
body: <p>I am doing the AOC challenege day 2, and I have written the below code to traverse an iterator holding the quiz input. The idea is to dump the input into the vector, go through the vector to parse it and do the challenge. I am using vectors for learning purposes,</p>
  <p>But for cout in the for (i: arr) it is not working. they only print the first item and wont print anything else. I ran it through the debugger it is definetly traversing the entire vector but cout only prints this:</p>
  <p><code>startforward 8f</code></p>
  <pre><code>//============================================================================
  // Name        : hello.cpp
  // Author      :
  // Version     :
  // Copyright   : Your copyright notice
  // Description : Hello World in C++, Ansi-style
  //============================================================================
  
  
  // reading a text file
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main () {
    string line;
    ifstream myfile (&quot;/home/user/eclipse-workspace/AOC2/puzzleinput/C2a_input.txt&quot;);
    vector&lt; string &gt; arr;
  
    cout &lt;&lt; &quot;start&quot;;
  
  
  
    if (myfile.is_open())
    {
      int i=0;
  
      while ( getline (myfile,line) )
      {
          arr.push_back(line);
  
  
  
          i++;
  
      }
      myfile.close();
  
    }
  
    else {cout &lt;&lt; &quot;Unable to open file&quot;;}
    //file is read, now we calculate hor and depth
  
    int horizontal = 0;
    int depth = 0;
  
    for (auto i : arr){
        cout &lt;&lt; i;
        cout &lt;&lt; i[0];
        cout &lt;&lt; i[sizeof(i)-1];
        if (i[0]=='f') {
            horizontal += i[sizeof(i)-1];
        } //forward
        if (i[0]=='u') {
            depth -= i[sizeof(i)-1];
        } //up
        if (i[0]=='d') {
            depth += i[sizeof(i)-1];
        } //down
  
  
  
    }
  
    cout &lt;&lt; depth*horizontal;
  
  
  
  
  
    return 0;
  }
  
  </code></pre>
  <p>the quiz input is as follows:</p>
  <pre><code>forward 8
  down 8
  ...etc
  </code></pre>