With unopened I mean:
ofstream outFile;
outFile << "Some text";
So I put text in an ofstream without call the .open() method. g++ does not complain, so maybe I still can save the data? How?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The stream will be in a failure state after you do this (
outFile.fail()will be true). The text isn’t stored anywhere, so no, you can’t save it.If you want to store data in memory, use an
std::ostringstream(from the<sstream>header) instead.