gpt4 book ai didi

c++ - 在 hdf5 中使用 std::string 会产生不可读的输出

转载 作者:太空狗 更新时间:2023-10-29 23:01:00 34 4
gpt4 key购买 nike

我目前在 Windows 7 64 位上使用 hdf5 1.8.15。我的软件的源代码使用utf8编码保存在文件中。

只要我调用任何支持 std::字符串的 hdf5 函数,输出就会变得神秘

enter image description here

但是如果我使用 const char* 而不是 std::string,一切正常。这也适用于文件名。

这是一个简短的示例:

std::string filename_ = "test.h5";    
H5::H5File file( filename_.c_str(), H5F_ACC_TRUNC); // works

H5::H5File file( filename_, H5F_ACC_TRUNC); // filename is not readable or
// hdf5 throws an exception

我猜想这个问题是由于我的源文件和hdf5使用了不同的编码引起的。但我对此不确定,并且没有找到允许使用 std::string 的解决方案。如果有任何想法可以帮助我解决这个问题,我将不胜感激。

最佳答案

我也有同样的问题,并通过将我所有的 std::string 或 h5std_string 改为字面意思来修复它:

5File file("myFile.h5", H5F_ACC_TRUNC);

或者使用string.c_str()将字符串更改为const char

关于c++ - 在 hdf5 中使用 std::string 会产生不可读的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32072272/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com