title: Access a vector like an array[] inside a function
body: <p>I want to access the vector in the "manipulatevector" function below the same way as i access an array with vector[i] and not vector->at(i) in the code below. I have tried to pass the vector directly, and not a pointer as can be done with arrays. But this seem to corrupt the program. Any ideas how this can be achieved? Im new to using the std library, as i mostly have experience from C.</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  #define vectorsize 5
  struct st_test {
      int ii;
      float dd;
  };
  
  void manipulatevector(std::vector&lt;struct st_test&gt; *test) {
      test-&gt;resize(vectorsize);
  
      for(int i=0;i&lt;vectorsize;i++) {
          test-&gt;at(i).dd = i*0.4f;
          test-&gt;at(i).ii = i;
      }
  }
  
  void manipulatearray(struct st_test test[vectorsize]) {
      for(int i=0;i&lt;vectorsize;i++) {
          test[i].dd = i*0.4f;
          test[i].ii = i;
      }
  }
  
  void main() {
      std::vector&lt;struct st_test&gt; test1;
      manipulatevector(&amp;test1);
  
      struct st_test test2[vectorsize];
      manipulatearray(test2);
  
      std::cout &lt;&lt; "Vector" &lt;&lt; std::endl;
      for(int i=0;i&lt;vectorsize;i++) {
          std::cout &lt;&lt; test1.at(i).dd &lt;&lt; std::endl;
      }
  
      std::cout &lt;&lt; "Array" &lt;&lt; std::endl;
      for(int i=0;i&lt;vectorsize;i++) {
          std::cout &lt;&lt; test2[i].dd &lt;&lt; std::endl;
      }
  }
  </code></pre>