Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将字符串附加到C++的HDF5数据集?_C++_Hdf5 - Fatal编程技术网

如何将字符串附加到C++的HDF5数据集?

如何将字符串附加到C++的HDF5数据集?,c++,hdf5,C++,Hdf5,我想向维度为1的HDF5数据集追加一个字符串。以下代码用于将double追加到文件test-doubles.h5中的doubles数据集中,但代码segfaults位于dataset.writestr、string_type、mspace、fspace call中: 非常感谢你的帮助 我使用以下命令将字符串写入H5文件: void writeString(const H5::CommonFG& fg, const string& name, const string& s

我想向维度为1的HDF5数据集追加一个字符串。以下代码用于将double追加到文件test-doubles.h5中的doubles数据集中,但代码segfaults位于dataset.writestr、string_type、mspace、fspace call中:


非常感谢你的帮助

我使用以下命令将字符串写入H5文件:

void writeString(const H5::CommonFG& fg, const string& name, const string& s)
{
    H5::StrType h5stringType(H5::PredType::C_S1, s.length() + 1); // + 1 for trailing zero
    H5::DataSet ds = fg.createDataSet(name, h5stringType, H5::DataSpace(H5S_SCALAR));
    ds.write(s, h5stringType);
    return;
}

int main() {
    H5::H5File file;
    file = H5::H5File(filename, H5F_ACC_EXCL);
    H5::Group group = h5Model.createGroup("/test");
    writeString(group, "string name", "value");
}

如果你换了新的,一切都会好起来的

dataset.write(str, string_type, mspace, fspace);


写字符串不是问题,问题是将字符串附加到具有H5S_无限维的数据集。哦,我明白了。我读它是因为你想附加到文件中。你能提供调试信息而不是仅仅说它是错误吗?见下面我的答案。但是如何从HDF5读回矢量呢?我想要一个不使用H5::DataSet::readH5std_字符串&,const数据类型&…的解决方案。。。请回答
dataset.write(str, string_type, mspace, fspace);
dataset.write(&str, string_type, mspace, fspace);