Why
#include <string> #include <fstream> void touch(const std::string& name) { if (!name.empty()) std::ofstream f(name); } void main() { touch("foo"); }
creates the file "foo" if it did not exist, but
#include <string> #include <fstream> void touch(const std::string& name) { if (!name.empty()) std::ofstream(name); } void main() { touch("foo"); }
does not create?
(Visual Studio 2015 Update 2)
name
with the typestd::ofstream
with a constructor without parameters. - Vladimir Gamalyan