I am trying to create istreamone that is read directly from the raw memory buffer.
I found a good way to do this in another post here:
class membuf : public basic_streambuf<char>
{
public:
membuf(char* p, size_t n) {
setg(p, p, p + n);
}
};
Then I create my own istreamusing this membuf:
membuf mb(dataPointer, dataLength);
istream reader(&mb);
Then I read using the getline()and operators >>, and everything is fine. However, I can not use seekg()to rewind back to the beginning of my buffer, but istream::tellg()always returns -1.
Do I need to write some more code to make them work, or is it doomed to failure?
source
share