Cython C++和std :: string

dsi*_*ign 12 c++ python cython

从cython使用C++标准std :: string的最佳方法是什么?最后的cython发行版应该会让它变得简单,但我想知道为什么有std :: vector的包装器而不是std :: string ...

Jim*_*son 15

Cython 0.16 包含std :: string的包装器,可以使用以下命令导入:

from libcpp.string cimport string
Run Code Online (Sandbox Code Playgroud)


dsi*_*ign 8

哎呀,这个问题已经挂了好几天了.最后我这样做了:

cdef extern from "string" namespace "std":
    cdef cppclass string:
        char* c_str()
Run Code Online (Sandbox Code Playgroud)

这不是一个完整的解决方案,但它仍然做到了.