Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython C++ and std::string

Tags:

c++

python

cython

What is the best way of using C++ standard std::string from cython? The last cython distribution should make it easy anyway, but I wonder why there are wrappers for std::vector and not for std::string...

like image 895
dsign Avatar asked Oct 06 '10 08:10

dsign


People also ask

Can you use std::string in C?

The std::string class manages the underlying storage for you, storing your strings in a contiguous manner. You can get access to this underlying buffer using the c_str() member function, which will return a pointer to null-terminated char array. This allows std::string to interoperate with C-string APIs.

Can you use C++ in Cython?

Overview. Cython has native support for most of the C++ language. Specifically: C++ objects can be dynamically allocated with new and del keywords.

Does Cython use C or C++?

Cython improves the use of C-based third-party number-crunching libraries like NumPy. Because Cython code compiles to C, it can interact with those libraries directly, and take Python's bottlenecks out of the loop.

What does std::string () do?

std::string class in C++ C++ has in its definition a way to represent a sequence of characters as an object of the class. This class is called std:: string. String class stores the characters as a sequence of bytes with the functionality of allowing access to the single-byte character.


1 Answers

Cython 0.16 includes wrappers for std::string, which can be imported with:

from libcpp.string cimport string
like image 142
Jim Garrison Avatar answered Sep 22 '22 02:09

Jim Garrison