我正在用 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)