Re:Appending to an std:string character-by-character: how do...
by gary_0 on Thursday October 26, 2023 @09:26PM
(#38033666)
Also I don't think the Standard requires that data() returns a valid pointer after only calling reserve(), so it's technically UB.
[ Parent
| on HN ]
Re:Appending to an std:string character-by-character: how do...
by zabzonk on Thursday October 26, 2023 @11:40PM
(#38034445)
i think you may have misunderstood the standard - data() will always return a valid pointer, but the pointer returned may be invalidated by any number of functions:
string s;
s.reserve(50);
char * p = s.data(); // ok so far
s.reserve(100); // now p may be invalid