Reading a string from hdf5 in C++

后端 未结 3 1653
有刺的猬
有刺的猬 2021-01-06 23:40

I am reading in datasets from a H5 file in Microsoft Visual C++ 2008. Everything works fine for data of type int and double but I run into problems when I come across string

3条回答
  •  日久生厌
    2021-01-07 00:28

    The HDF5 C++ API is woefully under-documented. This is how I read in strings from a dataset. I only figured this out with the help of a code-completion IDE:

    using namespace H5;
    std::string field_name("name of the field");
    StrType datatype(0, H5T_VARIABLE);
    DataSpace dataspace(H5S_SCALAR);
    DataSet datset = group.openDataSet(field_name);
    
    std::string field_value;
    datset.read(field_value, datatype, dataspace);
    

提交回复
热议问题