Convert iterator to pointer?

前端 未结 12 2282
野性不改
野性不改 2020-12-14 14:20

I have a std::vector with n elements. Now I need to pass a pointer to a vector that has the last n-1 elements to a function.

F

12条回答
  •  Happy的楠姐
    2020-12-14 14:32

    here it is, obtaining a reference to the coresponding pointer of an iterator use :

    example:

    string my_str= "hello world";
    
    string::iterator it(my_str.begin());
    
    char* pointer_inside_buffer=&(*it); //<--
    

    [notice operator * returns a reference so doing & on a reference will give you the address].

提交回复
热议问题