贡献者: addis
sudo apt install libhdf5-dev
#include <iostream>
#include <vector>
#include <H5Cpp.h>
// Use the standard HDF5 namespaces
using namespace H5;
using namespace std;
int main() {
vector<double> data = {1., 2., 3., 4., 5., 6.};
// H5F_ACC_TRUNC: replace file if exist
H5File file("testfile.h5", H5F_ACC_TRUNC);
hsize_t dims[2] = {2, 3}; // array size (ROW major!)
DataSpace dataspace(2, dims);
// use Predfined Type (PredType), double
DataSet dataset = file.createDataSet("myDoubleArray",
PredType::NATIVE_DOUBLE, dataspace);
dataset.write(data.data(), PredType::NATIVE_DOUBLE);
// will be auto called in destructors
dataset.close(); dataspace.close(); file.close();
}
dpkg -L libhdf5-dev
来查看所有头文件和 lib 文件的安装路径。
g++ test_hdf5.cpp -o test_hdf5.x -I/usr/include/hdf5/serial/ -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ -lhdf5_cpp -lhdf5
test_hdf5.x
dataset
时添加一个 DSetCreatPropList
(property list):
DSetCreatPropList plist;
plist.setDeflate(6); // compression level from 0 to 9
DataSet dataset = file.createDataSet("myDoubleArray",
PredType::NATIVE_DOUBLE, dataspace, plist);
 
 
 
 
 
 
 
 
 
 
 
友情链接: 超理论坛 | ©小时科技 保留一切权利