c# hdf5 写string_从C ++中的hdf5读取字符串

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 strings. In the H5 file I have 18 strings each of fixed length 24. My code is as follows;

StrType strdatatype(PredType::C_S1, 24);

char *buffer1[18];

DataSet datasetCurveNames = riskFactorsH5.openDataSet("/gstrCurveNames");

datasetCurveNames.read(&buffer1, strdatatype);

On execution buffer1 is filled with bad pointers. As an alternative I have tried using H5T_VARIABLE to manage variable length strings with the modification:

StrType strdatatype(PredType::C_S1, H5T_VARIABLE);

This also fails. If anyone can shed some light on this issue it would be much appreciated.

Cheers,

Lucas

解决方案

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值