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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:27:06+00:00 2026-06-17T20:27:06+00:00

In my program I used wstring to print out text I needed but it

  • 0

In my program I used wstring to print out text I needed but it gave me random ciphers (those due to different encoding scheme). For example, I have this block of code.

wstring text;
text.append(L"Some text");

Then I use directX to render it on screen. I used to use wchar_t but I heard it has portability problem so I switched to swtring. wchar_t worked fine but it seemed only took English character from what I can tell (the print out just totally ignore the non-English character entered), which was fine, until I switch to wstring: I only got random ciphers that looked like Chinese and Korean mixed together. And interestingly, my computer locale for non-unicode text is Chinese. Based on what I saw I suspected that it would render Chinese character correctly, so then I tried and it does display the charactor correctly but with a square in front (which is still kind of incorrect display). I then guessed the encoding might depend on the language locale so I switched the locale to English(US) (I use win8), then I restart and saw my Chinese test character in the source file became some random stuff (my file is not saved in unicode format since all texts are English) then I tried with English character, but no luck, the display seemed exactly the same and have nothing to do with the locale. But I don’t understand why it doesn’t display correctly and looked like asian charactor (even I use English locale).

Is there some conversion should be done or should I save my file in different encoding format? The problem is I wanted to display English charactore correctly which is the default.

  • 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-17T20:27:07+00:00Added an answer on June 17, 2026 at 8:27 pm

    Bug solved, it turns out to be the CASTING problem (not rendering problem as previously said).
    The bugged text is a intermediate product during some internal conversion process using swtringstream (which I forgot to mention), the code is as follows

    wstringstream wss;
    wstring text;
    textToGenerate.append(L"some text");
    wss << timer->getTime()
    text.append(wss.str());
    

    Right after this process the debugger shows the text as a bunch of random stuff but later somehow it converts back so it’s readable. But the problem appears at rendering stage using DirectX. I somehow left the casting for wchar_t*, which results in the incorrect rendering.

    old:

    LPCWSTR lpcwstrText = (LPCWSTR)textToDraw->getText(); 
    

    new:

    LPCWSTR lpcwstrText = (*textToDraw->getText()).c_str();
    

    By changing that solves the problem.

    So, this is resulted by a bad cast. As some kind people provided correction to my statement.

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

Sidebar

Related Questions

I used to program for iPhone. But then I want to make another similar
I'm trying to make a basic encryption program that used random numbers to encrypt
I need to write a program used internally where different users will have different
The below program is used to take the input of integers from a text
I solved Euler problem 14 but the program I used is very slow. I
In a program used to find words from random scrabble letters how do you
The following program used the implementation of atomic locks from 'Cuda By Example', but
I am creating a program used to connect to a embedded bluetooth device with
I'm developing a controller program used to run a humanoid kidsize robot. The OS
I recently wrote a program that used a simple producer/consumer pattern. It initially had

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.