Python list equivalent in C++?

前端 未结 5 983

Could you please tell me what is the closest data type in C++ to python list? If there is nothing similar, how would you build it in C++?

5条回答
  •  一生所求
    2021-02-05 17:53

    I am working on a wrapper for std::vector that makes it more like Python's lists named pylistpp. The API is just like Python. Example:

    #include 
    #include 
    
    int main()
    {
        list mylist;
        mylist.append(5);
        mylist.append(7);
        int count = mylist.count(5);
        std::cout << count << std::endl;
        std::cout << mylist.pop(0) << std::endl;
        std::cout << mylist.index(7);
        return 0;
    }
    

提交回复
热议问题