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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:33:46+00:00 2026-06-10T21:33:46+00:00

I’m linking a text file into my project by adding it to the resource

  • 0

I’m linking a text file into my project by adding it to the resource and then loading it.

I use LockResource and a static_cast to cast it to a std::wstring
std::wstring sData(static_cast<wchar_t*>(pData));

My project uses UNICODE (windows), which is why I’m using std::wstring and wchar_t.

I found out that I have to set the encoding in the file to UCS-2 LE, otherwise it would just read gibberish.
I’m guessing this is because that is what encoding Windows uses.

My question is, is it safe to assume all Windows operating systems currently use UCS-2 LE? I don’t want to run into a system using UCS-2 BE (or something else). My program would crash horribly.

I could save the file in ANSI, and then convert it to what ever encoding the operating system is using with MultiByteToWideChar, but this would be a waste of time if it’s definitely going to be UCS-2 LE.

  • 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-10T21:33:47+00:00Added an answer on June 10, 2026 at 9:33 pm

    All recent and current versions of Windows (excluding XBox) use UTF-16 LE.

    Note that there’s a bug with how you’re initializing the string variable:

    std::wstring sData(static_cast<wchar_t*>(pData));
    

    This assumes that the resource ends with a terminating (two-byte) 0, which I don’t think is guaranteed if you’re just referencing the file in your resources. You should get the size of the resource, and use the two-pointer constructor for sData.

    If you’re worried about time (as suggested by your comment on using MultiByteToWideChar), you should be aware that you’re copying the data from the resource into dynamic memory, and this copy is probably almost as slow as doing a conversion. If you’re doing this just once, I wouldn’t worry about the speed. I’d save the text as UTF-8, and use MultiByteToWideChar, especially if the UTF-8 encoding is more efficient for your text, as that would make your binary smaller.

    If speed is an issue (and if you don’t need to modify the string at run time), then I wouldn’t use a std::wstring at all. I’d make a class that provides a similar interface, but have it point directly to the resource memory rather than copy the entire text into dynamic memory. That saves load time and memory.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.