title: Converting an integer vector into a vector of byte arrays then calling each byte array
body: <p>I have a vector of numbers ex. <code>vector&lt;int&gt; vec={16383 1 8192}</code>. I need to convert them to byte arrays so that an SPI write function can read it and transfer data. I can't get a vector of byte arrays to work however. I'm new to C++. </p>
  
  <p>Basically, in case my code is unclear (which it probably is), I want to go from </p>
  
  <p><code>std::vector &lt;int&gt; output={16383,1,8192};</code></p>
  
  <p>to </p>
  
  <p><code>std::vector &lt;byte array&gt; finalbuffer= {{0,63,255},{0,0,1},{0,32,0}};</code></p>
  
  <p>so I can call <code>finalbuffer[0]</code> and it would contain <code>{0,63,255}</code>.</p>
  
  <p>I've tried looking up this problem, but the answers have been in float and not exactly what I need. I tried making an multi-dimensional array, however my initial vector size is not always the same and depends on data being read in.</p>
  
  <pre><code>std::vector &lt;int&gt; output={16383,1,8192};
  
  //the basic code to convert from integer to byte array, I don't know how 
  // to convert the int vector to a byte array vector 
  uint8 tx_buffer1[3] = { 0,0,0 };
     for (unsigned i = 0; i &lt; output.size(); ++i) {
           for (unsigned j = 0; j &lt; 3; ++j) {
                tx_buffer1[j] = (output[i] &gt;&gt; (2 - j) * 8) &amp; 0xFF;                     
                cout &lt;&lt; unsigned(tx_buffer1[j]) &lt;&lt; endl;               
                } 
  }
  
  //The above works such that
  int output=16383;
  uint8 tx_buffer1[3] = { 0,0,0 };
  for (unsigned j = 0; j &lt; 3; ++j) {
        tx_buffer1[j] = (output &gt;&gt; (2 - j) * 8) &amp; 0xFF;                    
         cout &lt;&lt; unsigned(tx_buffer1[j]) &lt;&lt; endl;              
          }   
  tx_buffer[0]=0
  tx_buffer[1]=63
  tx_buffer[2]=255
  // But I need it for multiple integers from the vector.
  </code></pre>
  
  <p>The below works with <code>uint8 finalbuffer= {0-255,0-255,0-255}</code>. <code>handle</code>, <code>&amp;transfercount</code> and <code>options</code> are unimportant. The 3 means it reads bytes, I need it so that the it will read an vector with a byte array in each element</p>
  
  <pre><code>std::vector &lt;byte array&gt; finalbuffer= {{0,63,255},{0,0,1},{0,32,0}};
  
  //finalbuffer[0] would contain {0,63,255}
  
  //finalbuffer[1] would contain {0,0,1}
  
  //...
  
  for {unsigned i=0; i&lt;finalbuffer.size(); ++i) {
  status = SPI_Write(handle, finalbuffer[i], 3, &amp;transferCount, options);
              if (status != FT_OK)
                  print_and_quit("Error while transmitting bytes.");
  }
  </code></pre>
  
  <p>I can't get my code to work. Is a better way of doing it that isn't a byte array vector?</p>