How can I get a pointer to the first element in an std::vector?

前端 未结 5 871
春和景丽
春和景丽 2020-12-15 03:33

I want to write data from an std::vector to a socket, using the write function, which has this prototype:

ssize_t write         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-15 03:47

    my_vec.empty() ? 0 : &my_vec.front()
    

    If you would like an std::out_of_range to be thrown if vector is empty, you could use

    &my_vec.at(0)
    

提交回复
热议问题