title: How to best write out a std::vector < std::string > container to a HDF5 dataset?
body: <p>Given a vector of strings, what is the best way to write them out to a HDF5 dataset?  At the moment I'm doing something like the following:</p>
  
  <pre><code>  const unsigned int MaxStrLength = 512;
  
    struct TempContainer {
      char string[MaxStrLength];
    };
  
    void writeVector (hid_t group, std::vector&lt;std::string&gt; const &amp; v)
    {
      //
      // Firstly copy the contents of the vector into a temporary container
      std::vector&lt;TempContainer&gt; tc;
      for (std::vector&lt;std::string&gt;::const_iterator i = v.begin ()
                                                , end = v.end ()
        ; i != end
        ; ++i)
      {
        TempContainer t;
        strncpy (t.string, i-&gt;c_str (), MaxStrLength);
        tc.push_back (t);
      }
  
  
      //
      // Write the temporary container to a dataset
      hsize_t     dims[] = { tc.size () } ;
      hid_t dataspace = H5Screate_simple(sizeof(dims)/sizeof(*dims)
                                 , dims
                                 , NULL);
  
      hid_t strtype = H5Tcopy (H5T_C_S1);
      H5Tset_size (strtype, MaxStrLength);
  
      hid_t datatype = H5Tcreate (H5T_COMPOUND, sizeof (TempConainer));
      H5Tinsert (datatype
        , "string"
        , HOFFSET(TempContainer, string)
        , strtype);
  
      hid_t dataset = H5Dcreate1 (group
                            , "files"
                            , datatype
                            , dataspace
                            , H5P_DEFAULT);
  
      H5Dwrite (dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &amp;tc[0] );
  
      H5Dclose (dataset);
      H5Sclose (dataspace);
      H5Tclose (strtype);
      H5Tclose (datatype);
  }
  </code></pre>
  
  <p>At a minimum, I would really like to change the above so that:</p>
  
  <ol>
  <li>It uses variable length strings </li>
  <li>I don't need to have a temporary container</li>
  </ol>
  
  <p>I have no restrictions over how I store the data so for example, it doesn't have to be a <em>COMPOUND</em> datatype if there is a better way to do this.</p>
  
  <p><strong>EDIT:</strong>  Just to narrow the problem down, I'm relatively familiar with playing with the data on the C++ side, it's the HDF5 side where I need most of the help.</p>
  
  <p>Thanks for your help.</p>