Is it legal to write to std::string?

后端 未结 5 941
孤街浪徒
孤街浪徒 2020-12-03 21:21

In std::string there are only const members to fetch the data like c_str(). However I can get a reference to the first element of the string via operator[] and

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 21:52

    std::string will be required to have contiguous storage with the new c++0x standard. Currently that is undefined behavior.

提交回复
热议问题