Using std:: string in hdf5 creates unreadable output

亡梦爱人 提交于 2019-12-07 12:56:09

问题


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

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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/32072272/using-std-string-in-hdf5-creates-unreadable-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!