Translating python dictionary to C++

前端 未结 7 1040
-上瘾入骨i
-上瘾入骨i 2020-11-30 00:57

I have python code that contains the following code.

d = {}

d[(0,0)] = 0
d[(1,2)] = 1
d[(2,1)] = 2
d[(2,3)] = 3
d[(3,2)] = 4

for (i,j) in d:
    print d[(         


        
7条回答
  •  庸人自扰
    2020-11-30 01:27

    std::map or more likely std::tr1::unordered_map / boost::unordered_map (aka hash_map) is what you want.

    Also, as kriss said, Boost.Python is a good idea to look at here. It provides a C++ version of python's dict class already, so if you're doing cross-language stuff, it might be useful.

提交回复
热议问题