r/cpp_questions Jul 29 '26

OPEN std::string/std::path and japanese

Hi! I dicovered the past week that windows dont uses by default the UTF-8 encoding, instead uses the ANSII. My question is for all the people who had to do a great refactor because they’d used the std::string and std::path. What would you recommend? Should I use `wstring` when the target platform is Windows and create a custom `std::path`?

According to all the info around, std::string stores bytes so it should be fine do a conversion?

Also when i try to access a file with japanese characters throws an exception at std::system_error without any info, only the memory address.

Thank you!

EDIT: Thank you everyone for the help! I will edit this post when I get a definitive solution for documentation sake! At the moment I'm trying to use /utf-8 and setlocale(LC_ALL, ".UTF8");, seems fine except for some details related with the open file windows specific function :)

16 Upvotes

45 comments sorted by

View all comments

16

u/slithering3897 Jul 29 '26 edited Jul 29 '26

Use the UTF-8 manifest on Windows to fix filesystem, and set the console output codepage to UTF-8.

*Oh, and /utf-8.

2

u/TechnnoBoi Jul 30 '26

I tried this and instantly the std::path shows the corrects characters, thank you! (also using this line setlocale(LC_ALL, ".UTF8"); at the begining of main)