1

My current code is:

namespace fs = std::filesystem;

void printAllInPath(std::filesystem::path a)
{
    for (auto const& dir_entry : fs::recursive_directory_iterator(a))
    {
        std::cout << dir_entry << "\n";
    }
}

The thing is, once it gets to a file with a special character in their name (like the special e, Chinese characters, symbols, etc.), it throws an exception, and my program goes kaput.

Is there a simple solution to this problem?

Thank you all in advance.

Anton C
  • 59
  • 4
  • Have you tried setting the *locale* before you read filenames? – Thomas Matthews Jun 10 '22 at 20:27
  • 1
    Have you tried using `std::wcout` instead of `std::cout`? You are forcing the library to convert Unicode characters to ANSI just to print them to a `char` stream, but Chinese and ANSI don't mix well. `fs::path` can handle Unicode paths just fine, you should print them as Unicode and not as ANSI. – Remy Lebeau Jun 10 '22 at 20:56
  • @RemyLebeau tried it, now it doesn't throw an exception, but rather, exits with code 0 as soon as it gets to the special characters, interesting... – Anton C Jun 11 '22 at 06:04

0 Answers0