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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:04:37+00:00 2026-05-17T18:04:37+00:00

I wrote the following program using VS2008: #include <fstream> int main() { std::wofstream fout(myfile);

  • 0

I wrote the following program using VS2008:

#include <fstream>
int main()
{
    std::wofstream fout("myfile");
    fout << L"Հայաստան Россия Österreich Ελλάδα भारत" << std::endl;
}

When I tried to compile it the IDE asked me whether I wanted to save my source file in unicode, I said “yes, please”.
Then I run the program, and myfile appeared in my project’s folder. I opened it with notepad, the file was empty. I recalled that notepad supported only ASCII data. I opened it with WordPad, it was still empty. Finally the little genius inside me urged me to look at the file size and not surprisingly it was 0 bytes. So I rebuilt and reran the program, to no effect. Finally I decided to ask very intelligent people on StackOverflow as to what I am missing and here I am 🙂

Edited:

After the abovementioned intelligent people left some comments, I decided to follow their advice and rewrote the program like this:

#include <fstream>
#include <iostream>
int main()
{
    std::wofstream fout("myfile");
    if(!fout.is_open())
    {
        std::cout << "Before: Not open...\n";
    }
    fout << L"Հայաստան Россия Österreich Ελλάδα भारत" << std::endl;
    if(!fout.good())
    {
        std::cout << "After: Not good...\n";
    }
}

Built it. Ran it. And… the console clearly read, to my surprise: “After: Not good…”.
So I edited my post to provide the new information and started waiting for answers which would explain why this is and what I could do. 🙂

  • 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-17T18:04:38+00:00Added an answer on May 17, 2026 at 6:04 pm

    In Visual studio the output stream is always written in ANSI encoding, and it does not support UTF-8 output.

    What is basically need to do is to create a locale class, install into it UTF-8 facet and then imbue it to the fstream.

    What happens that code points are not being converted to UTF encoding. So basically this would not work under MSVC as it does not support UTF-8.

    This would work under Linux with UTF-8 locale

    #include <fstream>
    int main()
    {
        std::locale::global(std::locale(""));
        std::wofstream fout("myfile");
        fout << L"Հայաստան Россия Österreich Ελλάδα भारत" << std::endl;
    }
    

    ~
    And under windows this would work:

    #include <fstream>
    int main()
    {
        std::locale::global(std::locale("Russian_Russia"));
        std::wofstream fout("myfile");
        fout << L"Россия" << std::endl;
    }
    

    As only ANSI encodings are supported by MSVC.

    Codecvt facet can be found in some Boost libraries. For example: http://www.boost.org/doc/libs/1_38_0/libs/serialization/doc/codecvt.html

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

Sidebar

Related Questions

I need to solve the following question which i can't get to work by
If I write a python script using only python standard libraries, using Python 2.6
I'm trying to write test harness for part of my Android mapping application. I
I have a project that adds elements to an AutoCad drawing. I noticed that
I would like to get a sum from a column, with and without a
I have a script that appends some rows to a table. One of 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.