#C++17 std::ifstream::open passing wchar_t* to fopen???

42 messages · Page 1 of 1 (latest)

coral quartz
#

Something about the docs doesn't make sense
https://en.cppreference.com/w/cpp/io/basic_filebuf/open.html

The file is opened as if by calling std::fopen with the second argument (file access mode) determined by the result of mode & ~std::ios_base::ate as follows, open() fails if the result is not some combination of flags shown in the table

->

Defined in header <cstdio>
        
std::FILE* fopen( const char* filename, const char* mode );
    

How is this possible???

runic dustBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

narrow solar
#

as if by calling std::fopen

coral quartz
narrow solar
#

it doesn't necessarily call std::fopen

coral quartz
#

so what does it call then

narrow solar
#

that's an implementation detail

coral quartz
#

bruh...

#

the docs dont say that at all

narrow solar
#

but it has the same effect as std::fopen

coral quartz
#

(I am talking about C++17 in Windows)

barren coyote
#

note that no const wchar_t* version exists anyways, that's an msvc extension

#

use std::filesystem::path

coral quartz
#

there is an overload in the standard

barren coyote
#

for filesystem path

#

not wchar_t

#

ah ok, the value type

#

well, that happens to be wchar_t on windows yeah

coral quartz
wooden fjord
#

if it causes bugs there that's a QOI issue

#

on windows it just calls _wfopen I think

coral quartz
coral quartz
coral quartz
#

okay, so it's safe to use for all filenames in windows

#

whew

coral quartz
wooden fjord
coral quartz
#

Found it

#

line 250

#

and _wsopen_s eventually will reach to _wfopen

#

Thank you for showing me the msvc internals

#

!solved