在hdf5中使用std :: string会创建不可读的输出 [英] Using std:: string in hdf5 creates unreadable output
问题描述
我目前在Windows 7 64bit上使用hdf5 1.8.15。
我的软件的源代码使用utf8编码保存在文件中。
I'm currently using hdf5 1.8.15 on Windows 7 64bit. The sourcecode of my software is saved in files using utf8 encoding.
一旦我调用任何支持std :: string的hdf5函数,ouput就会变得
As soon as I call any hdf5 function supporting std:: string, the ouput gets cryptic
但如果我使用 const char *
而不是 std :: string
,一切正常。这也适用于文件名。
But if I use const char*
instead of std::string
, everything works fine. This applies also to the filename.
这里是一个简短的示例:
Here is a short sample:
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
s。
I guess that this problem is caused by different encodings used in my source files and hdf5. But I'm not sure about this and found no solution allowing the use of std::string
s. I would appreciate any idea which helps me with this issue.
推荐答案
我也有同样的问题,并通过更改所有我的std :: string或h5std_string到字面上:
I also had the same problem, and fixed it by changing all my std::string or h5std_string to literally:
5File file("myFile.h5", H5F_ACC_TRUNC);
或使用 string.c_str()
将字符串更改为 const char
。
Or use string.c_str()
to change the string to const char
.
这篇关于在hdf5中使用std :: string会创建不可读的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!