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 6344893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:43:37+00:00 2026-05-24T20:43:37+00:00

I am using ICU’s ustdio functions to write a UnicodeString object to a file

  • 0

I am using ICU’s ustdio functions to write a UnicodeString object to a file in a range of encodings, however it doesn’t appear to prepend the BOM.

My Code:

void write_file(const char* filename, UnicodeString &str) {

    UFILE* f = u_fopen(filename, "w", NULL, "UTF-16 LE");
    u_file_write(str.getTerminatedBuffer(), str.length() + 1, f);
    u_fclose(f);
}

int _tmain(int argc, _TCHAR* argv[])
{
    UnicodeString str(L"ΠαρθένωνΗ");

    write_file("test.txt", str);

    return 0;
}

The file encoding does swap when I change LE to BE, however there is no BOM, the output file in a hex editor is:

A0 03 B1 03  C1 03 B8 03  AD 03 BD 03  C9 03 BD 03  97 03 00 00

NOTE: If I set the codepage as “UTF-16”, there is a BOM, however once I manually specify the endianness it disappears.

Alternatively is there a way I could write the UnicodeString to a file with a BOM?

  • 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-05-24T20:43:38+00:00Added an answer on May 24, 2026 at 8:43 pm

    Just guessing, the “UTF-16 LE” and “UTF-16 BE” were intended to be used when the byte order was well specified and the BOM would not be necessary in the context where the file would be used.

    You should be able to write your own BOM character '\ufeff' to the file.

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

Sidebar

Related Questions

Using ICU 4.0 regex library, I find that the following regex is exhibiting exponential
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I am using the ICU library in C++ on OS X. All of my
Is it possible to custom format currency strings using the ICU library similar to
Like the title says: can we use ...USING fts3(tokenizer icu th_TH, ...) . If
ICU provides a way of cutting down the size of the .dat file. I'm
Using the features currently available in PHP's intl wrapper for ICU, how would you
I have a text file which was created using some Microsoft reporting tool. The

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.