polskie znaki w std::filesystem::path

0

uruchamiam aplikacje konsolową w folderze "łłłóóóóńńńĘĘĘĘ"
i wyświetlam folder za pomocą funkcji std::filesystem::current_path()

jak aplikacja jest uruchomiona przez klikniecie w ikone to mam "┼é┼é┼é├│├│├│├│┼ä┼ä┼ä─ś─ś─ś─ś"
jak uruchomię cmd w folderze, potem "chcp 65001" i potem moją aplikację to już nazwa folderu się wyświetla
ale folderu z polskimi znakami juz nie utworzę

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main(int argc, char * argv[])
{
    std::cout << "current_path = " << fs::current_path() << '\n'; 


    fs::path p;
    std::cout << "create dir:";
    std::cin >> p;
    std::cout << "dir=>" << p <<"\n";
    fs::create_directory(p);


    std::cout << "press any key + ENTER";
    std::cin >> p;
}

testuje na Windows

2

spróbuj pobawić się z locale.

4

Dodaj do:

#include <iostream>
#include <filesystem>
#include <locale>

int main(int argc, char * argv[])
{
    std::locale::global(std::locale("Jakeś lokale charakterystyczne dla kodu .utf-8 powinno być ok"));
    std::cout.imbue(std::locale{""});
    std::cin.imbue(std::locale{""});

Kiedyś popełniłem taką odpowiedź na SO i nawet kiedyś przetłumaczyłem na polski.

3

A jeszcze jest taki wyjątek:
std::filesystem::path::path - cppreference.com

template< class Source >
path( const Source& source, const std::locale& loc, format fmt = auto_format );
(7)(since C++17)
template< class InputIt >
path( InputIt first, InputIt last, const std::locale& loc, format fmt = auto_format );
(8)(since C++17)

7-8) Constructs the path from a character sequence (format interpreted as specified by fmt) provided by source (7), which is a pointer or an input iterator to a null-terminated character sequence, an std::string, an std::basic_string_view, or represented as a pair of input iterators [first, last) (8). The only character type allowed is char. Uses loc to perform the character encoding conversion. If value_type is wchar_t, converts from to wide using the std::codecvt<wchar_t, char, std::mbstate_t> facet of loc. Otherwise, first converts to wide using the std::codecvt<wchar_t, char, std::mbstate_t> facet and then converts to filesystem native character type using std::codecvt<wchar_t,value_type> facet of loc.

1 użytkowników online, w tym zalogowanych: 0, gości: 1