小编Ant*_*ten的帖子

如何在 C++ 中操作 pybind11::dict

我正在用 C++ 编写一个接受 dict 的模块。

如何在 C++ 中操作 pybind11::dict

#include <pybind11/pybind11.h>
#include<iostream>
#include <pybind11/stl.h>
#include<map>

using namespace std;

namespace py = pybind11;

int main() {

    py::dict dict;
    dict["a"] = 1; // throws exception error - ptyes.h Line 546
    dict["b"] = 2; // throws exception error - ptyes.h Line 546

    for (auto item : dict)
    {
        std::cout << "key: " << item.first << ", value=" << item.second << std::endl;
    };
    system("pause");
    return 0;

}
Run Code Online (Sandbox Code Playgroud)

c++ python pybind11

3
推荐指数
1
解决办法
9751
查看次数

标签 统计

c++ ×1

pybind11 ×1

python ×1