I have created the very simple code snippet, compiled in Visual Studio 2022, to write a matrix object (STL vector of vectors containing double elements) into a directory. I’ve followed all the steps to ensure there are no errors/exceptions running the code in (e.g. linker errors, making sure the directory exists and contains no file with the same name, etc.). But for some strange reason, when I run the code below, no h5 file appears in the output directory, despite no errors or warnings! Is the code snippet working for other users?
#include <vector>
#include <string>
#include "H5Cpp.h"
int main()
{
using namespace H5;
// Create a compound data type for the inner vector
H5::CompType innerVectorType(sizeof(double));
innerVectorType.insertMember("inner", 0, H5::PredType::NATIVE_DOUBLE);
// Create a compound data type for the outer vector
H5::CompType outerVectorType(sizeof(innerVectorType));
outerVectorType.insertMember("outer", 0, innerVectorType);
std::string outputPath = "D://Scratch//Test.h5";
H5File file1(outputPath, H5F_ACC_EXCL);
std::vector<std::vector<double>> data = { {1.0, 2.0, 3.0},
{4.0, 5.0, 6.0},
{7.0, 8.0, 9.0} };
hsize_t dims[2] = { data.size(), data[0].size() };
H5::DataSpace dataspace(2, dims);
H5::DataSet dataset = file1.createDataSet("my_dataset", outerVectorType, dataspace);
// Write the data to the dataset
dataset.write(data.data(), outerVectorType);
return 0;
}