Can i safely use code like
fprintf(nullptr, "str");
or smth like
std::ofstream() << "str";
and
std::ofstream f;
f << "str";
Is there any descriptions of such situations in the C / C++ Standards?
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.
When using C++ streams the output operations have no effect when they are sent to stream with
std::ios_base::failbitorstd::ios_base::badbitset. If it is acceptable that the stream doesn’t indicate success, you can just create anstd::ostreamwith a null stream buffer:If you want the stream to also indicate success, you can just use it with a stream buffer indicating success from
overflow()andsync()but not doing anything.