What would be the easiest way to write a C++ vector<double>?


The C++ API examples use C arrays to write multidimensional datasets.

If I were to use the C++/C API to write simple 1D vectors, like

std::vector<double> errors (100, 0);

What would be the simplest way to achieve this using the C/C++ API? When I try to use create_dataset_double, the conversion to const double* naturally fails.



Usually &(errors[0]) is used to get a pointer to the underlying vector storage (note that vector storage is guaranteed to be contiguous). In that way you can use the C API. However, this cannot be done for bool vectors before C++11 since they are represented as bits.



Thanks Ger!

I am now having the same problem that I had with the C-API in terms of automatically creating nested groups. :expressionless:

The solution in the C API was to create the link creation property list, use


and pass the lcpl_id the ID of the link creation property list to H5Fcreate.

In the C++ API, the constructor of the H5::File class does not take the link creation property list as an argument, and there seems to be no link creatio property list available as a class in the C++ API.

So if I have a parameter study that I model in my C++ simulation software with multiple nested for loops, I need to manually create each sub-group in order to create the next one using the official C++ API?


We added the link creation property list for C++ to HDF5-1.10.2, but unfortunately did not include the H5Pset_create_intermediate API. I added bug HDFFV-10622 for it to be added to the C++ APIs.

Please note that the most current C++ documentation is now located here:



If you have access to C++11 (hoping you do at this point), then you can use:

errors.data(); instead of the &(errors[0]) workaround.

I also wrote this templated function years ago but we still use it in our production code. The complete context of the function can be found at https://github.com/BlueQuartzSoftware/SIMPL/blob/develop/Source/H5Support/H5Lite.h

Code below starts on line 234 of the file above. Hope this helps.
* @brief Creates a Dataset with the given name at the location defined by loc_id