Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // I memory map a file using mapped_file_source from boost which has these two members ...
- class mapped_file_source {
- // ...
- size_type size() const;
- const char* data() const; // ...
- };
- // I'm trying to put data into an istream so that I can parse the data line by line.
- struct membuf : streambuf
- {
- membuf(char* begin, char* end) {
- this->setg(begin, begin, end);
- }
- };
- // ....
- membuf sbuf(const_cast<char *>(map.data()), map.size());
- istream in(&sbuf);
- while (getline(in, line)) {
- // do stuff w/ line
- }
- /*
- test.cpp:49:54: error: invalid conversion from ‘boost::iostreams::mapped_file_source::size_type {aka long unsigned int}’ to ‘char*’ [-fpermissive]
- membuf sbuf(const_cast<char *>(map.data()), map.size());
- ^
- The problem is that setg takes char *'s and map.size() returns size_type (a.k.a. long unsigned int).
- Other thoughts on how to get data into an istream from a 'const char*' that is as efficient as possible?
- */
Advertisement
Add Comment
Please, Sign In to add comment