tellg and seekg not working when wrap vector<char> in istream

4063 views c++
4

As this link [https://stackoverflow.com/a/8815308/1068715] said:

I use setg(vec.data(), vec.data(), vec.data() + vec.size()); to initialize a streambuf. After that, read() on istream working properly, but tellg() always return -1, and seekg() always failed.

anyone can help?

answered question

1 Answer

3

seekg and tellg ask the streambuf via pubseekoff and pubseekpos to actually perform the work. The default implementation of these functions simply fail.

You need to implement seekoff and seekpos in your streambuf.

posted this

Have an answer?

JD

Please login first before posting an answer.