I am trying to write a stringstream
into a file but it not working.
int main() {
std::stringstream stream;
stream << "Hello world";
cout << stream.rdbuf()<<endl;//prints fine
std::ofstream p{ "hi.txt" };
p << stream.rdbuf();//nothing is writtten
p.close();
std::ifstream ip{ "hi.txt" };
std::string s;
ip >> s;
cout << s;//nothing printed
p.close();
return 0;
}
This answer here follows the same process. But it's not working in my case.