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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:01:58+00:00 2026-06-01T00:01:58+00:00

I am currently writing an application which requires me to call GetWindowText on arbitrary

  • 0

I am currently writing an application which requires me to call GetWindowText on arbitrary windows and store that data to a file for later processing. Long story short, I noticed that my tool was failing on Battlefield 3, and I narrowed the problem down to the following character in its window title:
http://www.fileformat.info/info/unicode/char/2122/index.htm

So I created a little test app which just does the following:

std::wcout << L"\u2122";

Low and behold that breaks output to the console window for the remainder of the program.

Why is the MSVC STL choking on this character (and I assume others) when APIs like MessageBoxW etc display it just fine?

How can I get those characters printed to my file?

Tested on both VC10 and VC11 under Windows 7 x64.

Sorry for the poorly constructed post, I’m tearing my hair out here.

Thanks.

EDIT:

Minimal test case

#include <fstream>
#include <iostream>

int main()
{
  {
    std::wofstream test_file("test.txt");
    test_file << L"\u2122";
  }

  std::wcout << L"\u2122";
}

Expected result: ‘™’ character printed to console and file.
Observed result: File is created but is empty. No output to console.

I have confirmed that the font I”m using for my console is capable of displaying the character in question, and the file is definitely empty (0 bytes in size).

EDIT:

Further debugging shows that the ‘failbit’ and ‘badbit’ are set in the stream(s).

EDIT:

I have also tried using Boost.Locale and I am having the same issue even with the new locale imbued globally and explicitly to all standard streams.

  • 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-01T00:01:59+00:00Added an answer on June 1, 2026 at 12:01 am

    To write into a file, you have to set the locale correctly, for example if you want to write them as UTF-8 characters, you have to add

    const std::locale utf8_locale
                = std::locale(std::locale(), new std::codecvt_utf8<wchar_t>());
    test_file.imbue(utf8_locale);
    

    You have to add these 2 include files

    #include <codecvt>
    #include <locale>
    

    To write to the console you have to set the console in the correct mode (this is windows specific) by adding

    _setmode(_fileno(stdout), _O_U8TEXT);
    

    (in case you want to use UTF-8).

    For this you have to add these 2 include files:

    #include <fcntl.h>
    #include <io.h>
    

    Furthermore you have to make sure that your are using a font that supports Unicode (such as for example Lucida Console). You can change the font in the properties of your console window.

    The complete program now looks like this:

    #include <fstream>
    #include <iostream>
    #include <codecvt>
    #include <locale>
    #include <fcntl.h>
    #include <io.h>
    
    int main()
    {
    
      const std::locale utf8_locale = std::locale(std::locale(),
                                        new std::codecvt_utf8<wchar_t>());
      {
        std::wofstream test_file("c:\\temp\\test.txt");
        test_file.imbue(utf8_locale);
        test_file << L"\u2122";
      }
    
      _setmode(_fileno(stdout), _O_U8TEXT);
      std::wcout << L"\u2122";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing an application using Vala that requires me to send data over
I am currently writing an application that requires bulk operations on a key/value store,
I'm currently writing a C# application that does a lot of digital signal processing,
I am currently writing a Comet application which requires me to send chunks of
I'm currently writing a web application which uses forms and PHP $_POST data (so
i am writing a small android application which requires some data which is stored
I am currently writing an API and an application which uses the API. I
At the office we are currently writing an application that will generate XML files
I'm currently writing an iPhone application that uses a UITabBarController with more than 5
I am looking at re-writing an application (currently in C) which uses HIS 2004

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.