You can use the std :: getline function in a while loop to display data in istream. Here is an example that I ran and it worked correctly:
#include <iostream> #include <sstream> #include <istream> #include <string> int main() { std::stringstream s1("This is a test string\nWith two lines"); std::istream s2(s1.rdbuf()); //just creates the istream to start with std::string stt; while(std::getline(s2,stt)) //can also have delimiter in getline { std::cout<<stt<<std::endl; } return 0; }
Run it and it will display:
This is a test string With two lines
I also tried this to use an istream pointer like yours:
#include <iostream> #include <sstream> #include <istream> #include <string> int main() { std::stringstream s1("This is a test string\nWith three lines); std::istream s2(s1.rdbuf()); //just creates istream to start with std::istream *s3 = &s2; //and use a pointer to istream like code at top std::string stt; while(std::getline(*s3,stt,'\n')) { std::cout<<stt<<std::endl; //result. } return 0; }
This code worked and gave the same result as me, without using a pointer. I could not reproduce your error. So the problem looks like creating your istream (e.g. istream * stream = res-> getBlob (1);).
user5732391
source share