Microsoft _setmode(), wcout wcin . , , , clang++, g++ MSV++:
#include <iostream>
#include <locale>
#include <locale.h>
#include <stdlib.h>
#ifndef MS_STDLIB_BUGS
# if ( _MSC_VER || __MINGW32__ || __MSVCRT__ )
# define MS_STDLIB_BUGS 1
# else
# define MS_STDLIB_BUGS 0
# endif
#endif
#if MS_STDLIB_BUGS
# include <io.h>
# include <fcntl.h>
#endif
#if !HAS_APP17_FILESYSTEM && !HAS_TS_FILESYSTEM && __has_include(<filesystem>)
# include <filesystem> /* MSVC has this header, but not the standard API. */
# if __cpp_lib_filesystem >= 201703
# define HAS_CPP17_FILESYSTEM 1
# endif
#endif
#if !HAS_CPP17_FILESYSTEM && __has_include(<experimental/filesystem>)
# include <experimental/filesystem>
# if __cpp_lib_experimental_filesystem >= 201406 || MS_STDLIB_BUGS
# define HAS_TS_FILESYSTEM 1
# endif
#endif
#if HAS_CPP17_FILESYSTEM
using std::filesystem::absolute;
using std::filesystem::current_path;
using std::filesystem::directory_entry;
using std::filesystem::directory_iterator;
using std::filesystem::is_directory;
using std::filesystem::exists;
using std::filesystem::path;
#elif HAS_TS_FILESYSTEM
using std::experimental::filesystem::absolute;
using std::experimental::filesystem::current_path;
using std::experimental::filesystem::directory_entry;
using std::experimental::filesystem::directory_iterator;
using std::experimental::filesystem::is_directory;
using std::experimental::filesystem::exists;
using std::experimental::filesystem::path;
#else
# error "This library has neither <filesystem> nor <experimental/filesystem>."
#endif
void init_locale(void)
{
#if MS_STDLIB_BUGS
constexpr char cp_utf16le[] = ".1200";
setlocale( LC_ALL, cp_utf16le );
_setmode( _fileno(stdout), _O_WTEXT );
#else
constexpr char locale_name[] = "";
setlocale( LC_ALL, locale_name );
std::locale::global(std::locale(locale_name));
std::wcin.imbue(std::locale())
std::wcout.imbue(std::locale());
#endif
}
using std::endl;
int main( const int argc, const char * const argv[] )
{
init_locale();
const path cwd = (argc > 1) ? absolute(path( argv[1], std::locale() ))
: absolute(current_path());
if (exists(cwd)) {
std::wcout << cwd.wstring() << endl;
} else {
std::wcerr << "Path does not exist.\n";
return EXIT_FAILURE;
}
if (is_directory(cwd)) {
for ( const directory_entry &f : directory_iterator(cwd) )
std::wcout << f.path().filename().wstring() << endl;
}
return EXIT_SUCCESS;
}
Thats, , , : std::filesystem 2018 , <experimental/filesystem> .
, , wcout :
#include <iostream>
#include <locale>
#include <locale.h>
#ifndef MS_STDLIB_BUGS
# if ( _MSC_VER || __MINGW32__ || __MSVCRT__ )
# define MS_STDLIB_BUGS 1
# else
# define MS_STDLIB_BUGS 0
# endif
#endif
#if MS_STDLIB_BUGS
# include <io.h>
# include <fcntl.h>
#endif
void init_locale(void)
{
#if MS_STDLIB_BUGS
constexpr char cp_utf16le[] = ".1200";
setlocale( LC_ALL, cp_utf16le );
_setmode( _fileno(stdout), _O_WTEXT );
#else
constexpr char locale_name[] = "";
setlocale( LC_ALL, locale_name );
std::locale::global(std::locale(locale_name));
std::wcin.imbue(std::locale())
std::wcout.imbue(std::locale());
#endif
}