title: HDF5 Cpp - retrieving the names of all groups in a file
body: <p>I try to read and save the names of all groups in a file (in die root-group of the file).
  So I use <code>H5Literate</code> to iterate over all objects in the root-group.</p>
  
  <p>My problem is, that I can print the names of the groups but I don't know how I can save them in an array.</p>
  
  <p>My operator function looks like this:</p>
  
  <pre><code>extern "C" herr_t file_info(hid_t loc_id, int *mom, string *Moments, const char *name, const H5L_info_t *linfo,
  void *opdata);
  {
  hid_t group;
  
  group = H5Gopen2(loc_id, name, H5P_DEFAULT);
  
  cout &lt;&lt; "Name : " &lt;&lt; name &lt;&lt; endl;
  Moments[mom]=name;
  H5Gclose(group);
  mom++;
  return 0;
  }
  </code></pre>
  
  <p>the Iteration looks as follows:</p>
  
  <pre><code>Group *rootGr = new Group (file-&gt;openGroup("/"));
      hsize_t numMom = rootGr-&gt;getNumObjs();
  
      string Moments[numMom];
      int mom=0;
  
      herr_t idx = H5Literate(rootGr-&gt;getId(), H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
  </code></pre>
  
  <p>The <code>cout</code> works but I get an error when trying to save the name in <code>Moments[mom]</code>.</p>
  
  <p>What is wrong here?</p>
  
  <p>EDIT: Errors are:</p>
  
  <pre><code>invalid conversion from 'herr_t (*)(hid_t, int*, std::string*, const char*, const H5L_info_t*, void*) {aka int (*)(int, int*, std::basic_string&lt;char&gt;*, const char*, const H5L_info_t*, void*)}' to 'H5L_iterate_t {aka int (*)(int, const char*, const H5L_info_t*, void*)}' [-fpermissive]    C/C++ Problem
  
  Invalid arguments '
  Candidates are:
  int H5Literate(int, enum H5_index_t, enum {H5public.h:9387}, unsigned long long int *, int (*)(int, const char *, const {H5Lpublic.h:3236} *, void *), void *)
      Semantic Error
  
  invalid types 'std::string* {aka std::basic_string&lt;char&gt;*}[int*]' for array subscript   C/C++ Problem
  
    initializing argument 5 of 'herr_t H5Literate(hid_t, H5_index_t, H5_iter_order_t, hsize_t*, H5L_iterate_t, void*)' [-fpermissive] C/C++ Problem
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>I fixed it:</p>
  
  <p>I added a global</p>
  
  <pre><code>std::vector&lt;string&gt; GroupNames;
  </code></pre>
  
  <p>then my operator function lookes like this:</p>
  
  <pre><code>herr_t
  file_info(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *opdata)
  {
  hid_t group;
  
  group = H5Gopen2(loc_id, name, H5P_DEFAULT);
  
  GroupNames.push_back(name);
  cout &lt;&lt; "Name : " &lt;&lt; name &lt;&lt; endl;
  H5Gclose(group);
  return 0;
  }
  </code></pre>