简体   繁体   English

提升python-python缓冲区到C ++ std :: string

[英]boost python - python buffer to C++ std::string

I have a C++ function that takes one std::string as an argument and a python object that is a buffer. 我有一个C ++函数,该函数将一个std :: string作为参数和一个作为缓冲区的python对象。 I thought that I could pass the buffer directly and that Boost Python would convert it to a string automatically, but it does not: 我以为我可以直接传递缓冲区,而Boost Python会自动将其转换为字符串,但事实并非如此:

Boost.Python.ArgumentError: Python argument types in
    mod.decrypt(buffer)
did not match C++ signature:
    decrypt(std::string string_to_decrypt)

Is it necessary to write converters for this? 为此有必要编写转换器吗? I thought it would implicitly convert. 我认为它会隐式转换。 Thanks for any advice. 感谢您的任何建议。

The error message says it all - your signature is a string, but you're passing it a buffer. 错误消息说明了一切-您的签名是一个字符串,但是您正在将其传递给缓冲区。

It's not going to introspect the object to determine how to convert it - buffer could be anything. 它不会自省对象以确定如何转换它-缓冲区可以是任何东西。

You need to convert it. 您需要对其进行转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM