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

  • Home
  • SEARCH
  • 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 1107817
In Process

The Archive Base Latest Questions

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

I have the following piece of code in C++: #include <iostream> #include <fstream> #include

  • 0

I have the following piece of code in C++:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
    wstring ws1 = L"Infinity: \u2210";
    wstring ws2 = L"Euro: €";

    wchar_t w[] = L"Sterling Pound: £";

    wfstream out("/tmp/unicode.txt");
    out.write(ws1.c_str(), ws1.size());
    out << ws1 << endl << ws2 << endl << w << endl;
    out.flush();
    out.close();
}

The program compiles without problem but the file is never open let alone writen on. Moreover, if I use std::wcout I still don’t get the right output, just ? for the infinity and pound symbols.

My system is g++ 4.4.3 running an ubuntu linux 10.4 64bits.

  • 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-17T01:59:25+00:00Added an answer on May 17, 2026 at 1:59 am

    Always set the locale first… do locale::global( locale( "" ) );. Before that, you’re in plain C mode which knows nothing about UTF-8.

    On Darwin, this is broken, so I need to do setlocale( LC_ALL, "" );, but then your program works for me.

    Edit

    Oops, you got bit by two gotchas at once. Opening a wfstream with the default openmode does not create the file. I inadvertently fixed this to wofstream before running your program, and then forgot I did. Sorry. So:

    wofstream out("/tmp/unicode.txt");
    

    or

    wfstream out("/tmp/unicode.txt", ios::in | ios::out | ios::trunc );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
I have the following piece of code: #include <stdio.h> int main ( int argc,
I have the following piece of code pattern: void M1(string s, string v) {
I have a doubt in the following piece of code and its behaviour: #include
I have the following piece of code which replaces template markers such as %POST_TITLE%
I have the following piece of code in Visual C++ 2005 : : class
I have trouble with the following piece of code. When I go through with
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I use the following piece of code in an include file. Because it it
I have the following piece of code to replace all tokens in a given

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.