Boost::python str to std::string

As with everything in Boost::Python, it might not always be obvious how to best extract certain types to C++

One thing to remember is that most (if not all) C++ types are supported by boost::python::extract

So, to extract a std::string object from python, it’s best to use the extract function again:

std::string tmp;
tmp = boost::python::extract<std::string>("test");
std::cout << tmp << std::endl;

Assuming the python file:

# test.py
test = "This is a test script"

The C++ code above should print This is a test script

You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.