I have a code like:
char* text = ....
std::istringstream iss(text);
I know that here temporary std::string is constructed and it one more time is copied inside stringstream object. Is there a way to construct stream from char* without making copy of string.
Historically, this functionality was provided by the now deprecated std::istrstream:
The class
istrstreamimplements input operations on array-backed streams. It essentially wraps a raw array I/O device implementation (std::strstreambuf) into the higher-level interface ofstd::basic_istream.The typical implementation of
istrstreamholds only one non-derived data member: an object of typestd::strstreambuf.Notes
istrstreamhas been deprecated since C++98,std::istringstreamandboost::iostreams::array_sourceare the recommended replacements.
Thus, a current implementation meeting your requirements is boost::iostreams::array_source:
Overview
The class templates
basic_array_source,basic_array_sinkandbasic_arrayprovide access to a sequence of characters in memory. The array Devices do not manage the lifetimes of the underlying character sequences.Implementation
The array Devices are implemented as Direct Devices in order to provide efficient unbuffered access to the underlying character sequences.
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