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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:24:59+00:00 2026-05-31T02:24:59+00:00

The Windows API seems big on UNICODE , you make a new project in

  • 0

The Windows API seems big on UNICODE, you make a new project in Visual C++ and it sets it to UNICODE by default.
And me trying to be a good Windows programmer, I want to use UNICODE.

The problem is the C++ Standard Library and STL (such as std::string, or std::runtime_error) don’t work well with UNICODE strings.
I can only pass a std::string, or a char* to std::runtime_error, and i’m pretty sure std::string doesn’t support UNICODE.

So my question is, how should I use things such as std::runtime_error? Should I mix UNICODE and regular ANSI? (I think this is a bad idea…)
Just use ANSI in my whole project? (prefer not..) Or what?

  • 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-31T02:25:01+00:00Added an answer on May 31, 2026 at 2:25 am

    In general you shouldn’t mix those two encodings. However, exception messages are something that is only of interest to the developer (e.g. in log files) and should never be shown to the user (but look at Jim’s comment for an important caveat).

    So you are on the safe side if you use UNICODE for your whole user-faced interface and still use std::exception etc. behind the scenes for developer messages. There should be no need ever to convert between the two.

    Furthermore, it’s a good trick to define a typedef for UNICODE-independent strings in C++:

    typedef std::basic_string<TCHAR> tstring;
    

    … and analogously define tcout, tcin etc. conditionally:

    #ifdef UNICODE
        std::wostream& tcout = std::wcout;
        std::wostream& tcerr = std::wcerr;
        std::wostream& tclog = std::wclog;
        std::wistream& tcin = std::wcin;
    #else
        std::ostream& tcout = std::cout;
        std::ostream& tcerr = std::cerr;
        std::ostream& tclog = std::clog;
        std::istream& tcin = std::cin;
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to learn windows API and PInvoke methods just like MesseageBeep in User32.dll.
Given that the Windows API function GetGlyphIndices() can translate a 2 byte UNICODE char
Im trying to use a function from Windows API on delphi, functions for Windows
I'm wrapping the Windows API, and I wish to make error checking easy to
I'm trying to find out the 'correct' windows API for finding out the localized
Windows API ::FindWindow function fails when called from Service application. GetLastError() also returns 0
Using the Windows API, how can I get a list of domains on my
Are there Windows API functions that allows reading what the current password policy is?
Is there in Windows API or in MFC any analog to atoh() function? atoh()
Is there a Windows API or any way to determine on which physical processor/core

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.