How can I convert a C++ std::string object into a Ruby VALUE object?
I tried rb_str_new2(c_string), but it did not work.
I have a function
VALUE foo(){return rb_str_new2(c_string);};
and that gives an error message:
cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘const char*’ for argument ‘1’ to ‘size_t strlen(const char*)’
You are passing
std::stringto the function, but it expects a null-terminatedconst char *.The
std::string::c_str()member function can be used to get one: