I am just trying to open a group from a hdf database. I kept the group name in a string variable.But C++ compiler is giving the following error. I would like to stick with string since I am doing this in C++. Any solutions? Thank you
Reader.cpp: In constructor ‘Reader::Reader(std::string)’: Reader.cpp:5: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘2’ to ‘hid_t H5Gopen2(hid_t, const char*, hid_t)’
Reader.h
ifndef READER_H
#define READER_H
#include <string>
#include "H5Cpp.h"
#define FILEHDF "/media/data/back_up.h5"
class Reader
{
private:
hid_t file_id, dataset_id, dataspace_id, group_id,strtype, memtype;
hsize_t dims[1];
herr_t status;
std::string m_fasta;
Reader() {}
public:
Reader(std::string prot_name);
void SetFasta(std::string fasta);
std::string GetFasta() {return m_fasta;}
};
#endif
Reader.cpp
#include "Reader.h"
Reader::Reader(std::string prot_name)
{
file_id=H5Fopen(FILEHDF, H5F_ACC_RDWR, H5P_DEFAULT);
group_id=H5Gopen2(file_id, prot_name, H5P_DEFAULT); //error is coming from here
SetFasta(prot_name);
}
void Reader::SetFasta(std::string fasta)
{
m_fasta=fasta;
}
main.cpp
#include <iostream>
using namespace std;
#include <string>
#include "Reader.h"
#include "H5Cpp.h"
int main()
{ std::string prot_name, fasta_seq;
prot_name="102LA";
Reader rd(prot_name);
fasta_seq=rd.GetFasta();
cout<<fasta_seq;
return 0;
}