title: Possible to convert std::vector of std::pairs into a byte array?
body: <p>I am wondering if it is possible to convert vector of pairs into a byte array. </p>
  
  <p>Here's a small example of creating the vector of pairs:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      PBYTE FileData, FileData2, FileData3;
      DWORD FileSize, FileSize2, FileSize3;
  
      /* Here I read 3 files + their sizes and fill the above variables. */
  
      //Here I create the vector of std::pairs.
      std::vector&lt;std::pair&lt;PBYTE, DWORD&gt;&gt; DataVector
      {
          { FileData, FileSize }, //Pair contains always file data + file size.
          { FileData2, FileSize2 },
          { FileData3, FileSize3 }
      };
  
      std::cin.ignore(2);
      return 0;
  }
  </code></pre>
  
  <p>Is it possible to convert this vector into a byte array (for compressing, and writing to disk, etc)?</p>
  
  <p>Here is what I tried, but I didn't get even the size correctly:</p>
  
  <pre><code>PVOID DataVectorArr = NULL;
  
  DWORD DataVectorArrSize = DataVector.size() * sizeof DataVector[0];
  
  if ((DataVectorArr = malloc(DataVectorArrSize)) != NULL)
  {
      memcpy(DataVectorArr, &amp;DataVector[0], DataVectorArrSize);
  }
  
  std::cout &lt;&lt; DataVectorArrSize;
  
  //... Here I tried to write the DataVectorArr to disk, which obviously fails because the size isn't correct. I am not also sure if the DataVectorArr contains the DataVector now.
  
  if (DataVectorArr != NULL) delete DataVectorArr;
  </code></pre>
  
  <p>Enough code. Is is it even possible, or am I doing it wrong? If I am doing it wrong, what would be the solution? </p>
  
  <p>Regards, Okkaaj</p>
  
  <p>Edit: If it's unclear what I am trying to do, read the following (which I commented earlier):</p>
  
  <p>Yes, I am trying to cast the vector of pairs to a <code>PCHAR</code> or <code>PBYTE</code> - so I can store it to disk using WriteFile. After it is stored, I can read it from disk as byte array, and parse back to vector of pairs. Is this possible? I got the idea from converting / casting <code>struct</code> to a byte array and back(read more from here: <a href="https://stackoverflow.com/questions/13775893/converting-struct-to-byte-and-back-to-struct">Converting struct to byte and back to struct</a>) but I am not sure if this is possible with std::vector instead of structures.</p>