is there a way to std::basic_istream::get with a basic_streambuf to also read the delimeter char?

20 Views Asked by At

Given

#include<string>
#include<stringstream>
#include <fstream>

int main(int argc, char* args[])
{
  std::fstream  file("MyFile.txt", std::fstream::in);
  std::stringbuf sb;
  file.get(sb, '\0');
  file.get(); // (1) wasting the delimiter char
  
   return 0;
}

Basically, What I am looking for is to avoid doing the (1) statement as it looks just not tidy.

The (approximate) alternative workaround could be getline, but is not dynamically allocated like stringbuf as it requires a fixed size buffer, so it is not an equivalent solution in the case when using a std::basic_streambuf.

is there a way with std::basic_istream::get(basic_streambuf&, ...) to also read the delimiter char without forcing to the next statement to do a wasted .get?

0

There are 0 best solutions below