Using std:: string in hdf5 creates unreadable outp

2019-05-17 06:18发布

I'm currently using hdf5 1.8.15 on Windows 7 64bit. The sourcecode of my software is saved in files using utf8 encoding.

As soon as I call any hdf5 function supporting std:: string, the ouput gets cryptic

enter image description here

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

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::strings. I would appreciate any idea which helps me with this issue.

2条回答
Juvenile、少年°
2楼-- · 2019-05-17 06:45

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

Or use string.c_str() to change the string to const char.

查看更多
混吃等死
3楼-- · 2019-05-17 06:51

I had exactly the same problem. The solution was, that I was in Debug-Mode in Visual Studio, whereas the libraries I linked against were build in Release-Mode. When I switched in Visual Studio to Release-Mode, the above error disappeared.

查看更多
登录 后发表回答