Should I preallocate std::stringstream?

后端 未结 4 811
终归单人心
终归单人心 2020-12-16 10:39

I use std::stringstream extensively to construct strings and error messages in my application. The stringstreams are usually very short life automa

4条回答
  •  星月不相逢
    2020-12-16 11:16

    I'm not sure, but I suspect that stringbuf of stringstream is tightly related with resulted string. So I suspect that you can use ss.seekp(reserved-1); ss.put('\0'); to reserve reserved amount of bytes inside of underlying string of ss. Actually I'd like to see something like ss.seekp(reserved); ss.trunc();, but there is no trunc() method for streams.

提交回复
热议问题