Is there a string buffer class that provides an iterator that allocates a new buffer if necessary on incrementing (*++itr = 'x'
), or am I stuck with pre-allocating buffers first?
There is something called std::back_inserter()
, which calls push_back()
every time you assign to it. Some example code:
int main() {
string s = "abc";
auto it = std::back_inserter(s);
it = 'd';
cout << s << endl;
return 0;
}
Will print out: abcd
You can use std::ostringstream
with std::ostream_inserter
, something like this (untested):
std:::ostringstream stream;
auto itr = ostream_inserter<char>(stream);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With