7得票2回答
为什么我可以在临时的std::ofstream对象上使用`operator<<`运算符?

根据C++标准,您不能将临时对象绑定到非const引用。由于流输出运算符定义为: template &lt;class CharT, class Traits, class Allocator&gt; std::basic_ostream&lt;CharT, Traits&gt;&amp;...