c++ - Difference in c_str function specification between C++03 and C++11 -
in c++ reference of c_str()
in std::string
following appears:
return value
pointer underlying character storage.
data()[i] == operator[](i) every in [0, size())
(until c++11)
data() + == &operator[](i) every in [0, size()]
(since c++11)
i not understand difference between two, except range increase 1 element since c++11.
isn't former statement data()[i] == operator[](i)
true latter?
except range increment 1 element since c++11, there still big difference between:
data()[i] == operator[](i)
and:
data() + == &operator[](i)
that main difference &
operator in prototypes.
the old prototype, allowed copy made when write operation occur, since pointer returned point buffer 1 holding original string.
the other difference in prototypes between data()[i]
, data() + i
, not critical, since equivalent.
a difference between c++ , c++11 in former, std::string
not specified explicitly standard whether have null terminator or not. in latter however, specified.
in other words: will std::string null-terminated in c++11? yes.
Comments
Post a Comment