Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8645519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:34:18+00:00 2026-06-12T12:34:18+00:00

Everything what I want is just to create a file but with a correctly

  • 0

Everything what I want is just to create a file but with a correctly displayed name on Linux and Windows.

On Linux this code works fine and I think that it’s so because of properly handling of UTF-8.

On Windows there are some problems. I have two set languages English and Russian. If I use System Encoding in my programming environment (QT Creator) then the created file has almost correctly name, but to regret other letters from German, French (and I suspect Japan, Chinese are not exception) can’t be used in the name of file, otherwise , as one can see they are truncated. So, it’s a bad approach. Because names can be from any different language.

I.e. I wanted a name to look so:
string s="тдöüлотдFILE";

But it looks so:

enter image description here

I changed Encoding in Qt Creator to UTF-8 in hope that it will work correctly.

But now I get this:

string s="тдöüлотдFILE"; - expected name

Gotten name:
enter image description here
It looks even yet worse.

I tried to change encoding in Qt Creator to UTF-16 (I heard windows uses it), but as result compiler refuses to compile code in this encoding (the same is with UTF16LE,BE,UTF32)

Whole situation:

enter image description here

I suspect that problem lies in how Windows interpret names. But how can I say it to display it correctly as it ought to be and in the same time working on Linux?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:34:20+00:00Added an answer on June 12, 2026 at 12:34 pm

    Well, this doesn’t describe how to fix it, but I “need” more than 500 chars 🙂

    Before I try to explain (in a confusing way…) what the problem is that you are looking at: you might want to try to conditionalize the filename for the platforms (I can’t remember the official macros to identify each the platform, so please replace with the correct ones):

    #if defined(LINUX)
    const char* Filename="тдöüлотдFILE";
    #elif defined(WINDOWS)
    const wchar_t* Filename=L"тдöüлотдFILE";
    #endif
    
    fstream f(Filename,...);
    

    This still requires that your sourcecode is in whatever encoding your compiler expects. If that happens to be the system codepage, you might not even be able to ever get these characters into a string literal (but, if the wchar_t version works, you can also construct the filename using the integer codes for the characters. Less readable, but it doesn’t depend on the source file encoding).

    The problem you are dealing with is quite complex, and might be impossible to solve in an easy way.

    Windows is using UTF16 internally (since XP, 2000 and NT used UCS2, 9x and 3.x used codepages). Linux users have pretty much moved to UTF-8, although there are still developers that haven’t heard about that. But it’s improving.

    Now, while UTF-8 has a codepage value, it can’t actually be a system codepage. The codepage value is just for the functions that convert between codepages and UTF-16, but each system still has a legacy-codepage that is NOT UTF-8. The legacy or “ANSI” API on Windows takes strings encoded in the system codepage, whereas the Unicode API takes them in UTF-16. There is no other option.

    So, obviously, Windows programs like to use UTF-16. However, Linux doesn’t like it very much at all, they prefer UTF-8. I use a framework of my own to help leverage such problems (and other things, of course) between Windows, Linux and MacOS; existing frameworks such as Qt do it too. Without such help, the safest option is to stick to string literals in ASCII.

    Your IDE setting can only affect how the source code is stored; it can’t affect how the runtime treats literals, or what APIs are eventually used by the runtime.

    You can try to cook something up, such as using Microsofts “TCHAR” setup that was meant to allow programs to be compiled using “ANSI” (no, I have no idea why they chose that name) or Unicode with a simple switch. I’m not particular familiar with or interested in it, but it defines types (such as TCHAR for a single char) and macros for string literals, and causes the appropiate mapping for Windows API functions (like calls to ‘CreateFile’ will turn out to be calls to CreateFileW or CreateFileA). One option that comes to mind is to compile stuff as Unicode for windows, and typedef/define the appropiate stuff for Linux to produce the “char”-based variant of the code. You might also have to use std::basic_string instead of std::string.

    As a sidenote, VisualC++ 2012, to my knowledge, accepts source code in UTF-8 and UTF-16. I do not, however, know what it puts into “char*” literals (in my code, I only allow ASCII in such literals to be on the safe side. ‘Obscure’ characters come from string files anyway; I only need literals for filenames, registry keys, internal keys etc.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to setup jetty with jetty-blazeds extension. Everything looks fine but when I
I have this menu structure: http://jsfiddle.net/Rochefort/szL2C/ everything is ok. But i want, hover effect
When I want to implement ViewModel I should cut everything c# code from my
I have a simple xml file and I want to remove everything before the
I can run normally SQLAlchemy when everything is in one file. I now want
I want to create a file with a .aspx extension(or any other extension) completely
I have this delphi code that basically download a file (using Delphi 2010 +
I want to delete everything before the last tab (or comma). For example, in
Everything I'm finding via google is garbage... Note that I want the answer in
i want to make a php app that let people submit photos/videos/sounds Now, everything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.