initializing a C++ std::istringstream from an in memory buffer?

前端 未结 4 929
时光取名叫无心
时光取名叫无心 2020-11-30 06:22

I have a memory block (opaque), that I want to store in a Blob in mySQL through their C++ adapter. The adapter expects a istream:

virtual void setBlob(unsign         


        
4条回答
  •  萌比男神i
    2020-11-30 06:29

    Look at std::istrstream it has a constructor

     istrstream( char* pch, int nLength );
    

    This class is sort of depreciated or at least you are normally told to use other classes.
    The issue with strstream is that it is more complex to manage the memory of the char* buffer so in general you would prefer stringstream as it does the memory management for you. However in this case you are already managing the memory of the char* so the normal benefit is in this case a cost. In fact in this case strstream does exactly what you want with minimal overhead in code or speed. This is similar to the discussion of ostrsteram by Herb Sutter

提交回复
热议问题