Commit eaa8efb9 authored by Victor Zverovich's avatar Victor Zverovich

Fix ofstream handling in msvc

parent fb991e9d
...@@ -82,7 +82,9 @@ template class filebuf_access<filebuf_access_tag, ...@@ -82,7 +82,9 @@ template class filebuf_access<filebuf_access_tag,
&filebuf_type::_Myfile>; &filebuf_type::_Myfile>;
inline bool write(std::filebuf& buf, fmt::string_view data) { inline bool write(std::filebuf& buf, fmt::string_view data) {
print(get_file(buf), data); FILE* f = get_file(buf);
if (!f) return false;
print(f, data);
return true; return true;
} }
inline bool write(std::wfilebuf&, fmt::basic_string_view<wchar_t>) { inline bool write(std::wfilebuf&, fmt::basic_string_view<wchar_t>) {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
// //
// For the license information refer to format.h. // For the license information refer to format.h.
#include <fstream>
#include "fmt/format.h" #include "fmt/format.h"
using fmt::runtime; using fmt::runtime;
...@@ -297,3 +299,8 @@ TEST(ostream_test, is_formattable) { ...@@ -297,3 +299,8 @@ TEST(ostream_test, is_formattable) {
EXPECT_TRUE(fmt::is_formattable<std::string>()); EXPECT_TRUE(fmt::is_formattable<std::string>());
EXPECT_TRUE(fmt::is_formattable<fmt::detail::std_string_view<char>>()); EXPECT_TRUE(fmt::is_formattable<fmt::detail::std_string_view<char>>());
} }
TEST(ostream_test, closed_ofstream) {
std::ofstream ofs;
fmt::print(ofs, "discard");
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment