C++ std::string to Ruby VALUE
C++ std::string to Ruby VALUE
如何将C++ std::string
对象转换为Ruby VALUE
对象?
我尝试了rb_str_new2(c_string)
,但它不起作用。
我有一个功能
VALUE foo(){return rb_str_new2(c_string);};
这给出了一条错误消息:
cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘const char*’ for argument ‘1’ to ‘size_t strlen(const char*)’
您正在将std::string
传递给函数,但它需要以 null 结尾的const char *
。
std::string::c_str()
成员函数可用于获取一个:
rb_str_new_cstr(string.c_str());
相关文章:
- 递归列出所有目录中的C++与Python与Ruby的性能
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 为什么static_assert错误:即使我传递常量"expression must have a constant value"?
- 为什么我会" void value not ignored as it ought to be"?
- 方法错误"not all control paths return a value"和方法不返回值
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- 如何在 c++ 中理解这样的代码 [request->headers().Method()->value().getStringView())]
- std::<key-value>不同类型的对向量
- c++ visual studio 64bit | save registers value
- 初始化数组、"memset"或" {//value} "的最佳方法是什么?
- 如何解决类成员函数中的"return a value"错误?
- bsoncxx: document::view vs document::value
- .value( "key" , default) 不适用于空的 json 对象吗?
- 如何在C++中设置演员的"Render Custom Depth Pass"和"Depth Stencil Value"?
- Qt 错误:QSqlQuery::value:尝试从表中检索统计信息时未定位在有效记录上 (QComboBox)
- 按原样保存用户输入 - Ruby on Rails
- 马洛克会在 C++17 年返回"invalid pointer value"吗?
- 如何将 v8::FunctionCallbackInfo<v8::Value> 数组从一个隔离复制到另一个隔离?
- std::value templated 方法的函数使用 clang 和 g++ 进行编译,但不使用 msvc 进行编译
- C++ std::string to Ruby VALUE