Hello,
I have written a std::string with this code into a HDF5 file:
H5::DataSet l_dataset;
H5::DataSpace l_dataspace;
// create group
l_dataset.write( p_value.c_str(), H5::StrType(l_dataset), l_dataspace );
p_value ist the std::string, which should be written. The l_dataset is an object with the datatype like NATIVE_CHAR.
I write the data "abcd" into the file try reading them in matlab, I get in Matlab an array with [97, 98, 99, 100]. The array has the values of the chars a, b, c, d. How can I write a std::String with the HDF classes into a file?
Thanks
Phil
Hi,
I have written a std::string with this code into a HDF5 file:
Note that you write out the C-string obtained from the
std::string.
H5::DataSet l_dataset;
H5::DataSpace l_dataspace;
// create group
l_dataset.write( p_value.c_str(), H5::StrType(l_dataset),
l_dataspace );
p_value ist the std::string, which should be written. The l_dataset
is an object with the datatype like NATIVE_CHAR.
I write the data "abcd" into the file try reading them in matlab, I
get in Matlab an array with [97, 98, 99, 100]. The array has the
values of the chars a, b, c, d. How can I write a std::String with
the HDF classes into a file?
Since your code is not complete (it's unclear how 'l_dataset'
gets set up) I can only guess that you don't write the trai-
ling '\0' character into the file. That belongs to a C-string
and without it it's just a char array (the '\0' indicates were
the string ends). And thus MatLab probably treats it as just
another array of values and not as a string. So I would start
with making sure that 'p_value.length( ) + 1' values get written
to the HDF5 file.
Regards, Jens
···
On Sat, Apr 23, 2011 at 06:24:28PM +0200, Kraus Philipp wrote:
--
\ Jens Thoms Toerring ________ jt@toerring.de
\_______________________________ http://toerring.de