title: changing vector values within in a different function from where it was allocated c++
body: <p>This might be obvious but Im new to using vectors and could use some help. I have a vector i have defined in my main function and I want to change its values in a function call through referencing it like you would with an array.</p>
  
  <pre><code>int foo(vector&lt;float&gt; &amp;lines){
      lines[1] = 2.5;
      lines[2] = 1.2;
      //etc
  }
  
  int main(){
      vector&lt;float&gt; lines(3);
      lines[0] = 5.4;
      foo(lines);
  }
  </code></pre>
  
  <p>if I print off the vector values I get {5.4, 0, 0} what am I doing wrong?</p>
  
  <p>edit:
  Thanks for the help, Ive got it working now but to be honest Im not sure exactly what the problem was. Originally I was attempting to assign to the vector with this:</p>
  
  <pre><code>lines[lineCtr*2] = (float)rho;
  lines[(lineCtr*2)+1] = theta;
  </code></pre>
  
  <p>This worked when lines was an array but not as a vector. When I changed the assignment in the foo function to this:</p>
  
  <pre><code>int pos0 = lineCtr * 2;
  int pos1 = (lineCtr * 2) + 1;
  
  lines[pos0] = (float)rho;
  lines[pos1] = theta;
  </code></pre>
  
  <p>It works perfectly. Could anyone tell me why this is?</p>