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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:28:00+00:00 2026-06-18T12:28:00+00:00

#include <locale> #include <fstream> #include <iostream> using namespace std; int main() { ofstream fout(test.txt);

  • 0
#include <locale>
#include <fstream>
#include <iostream>

using namespace std;

int main()
{
    ofstream fout("test.txt");

    fout.imbue(locale("chs"));
    cout.imbue(locale("C"));

    cout.rdbuf(fout.rdbuf());
    cout << "中文"; // Which locale will apply to here? "C" or "chs"?
}

The question is commented in the code.

  • 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-18T12:28:01+00:00Added an answer on June 18, 2026 at 12:28 pm

    From http://www.cplusplus.com/reference/ios/ios/imbue/

    std::ios::imbue <ios>

    locale imbue ( const locale& loc );

    Imbue locale

    Associates loc to both the stream and its associated stream buffer (if
    any) as the new locale object to be used with locale-sensitive
    operations.

    All callback functions registered with register_callback with
    imbue_event as its first parameter are called.

    In fact, this member function calls its inherited homonym
    ios_base::imbue(loc), and if the stream is associated with a stream
    buffer, also calls rdbuf()->pubimbue(loc).

    Also, see http://stdcxx.apache.org/doc/stdlibug/27-4.html

    27.4.4 Collaboration of Locales and Iostreams

    The base class ios_base contains a locale object. The formatting and
    parsing functions defined by the derived stream classes use the
    numeric facets of that locale.

    The class template basic_ios holds a pointer to the stream buffer.
    This stream buffer has a locale object, too, usually a copy of the
    same locale object used by the functions of the stream classes. The
    stream buffer’s input and output functions use the code conversion
    facet of the attached locale.

    In your case, it would use the “C” numeric locale and the “chs” character locale.

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

Sidebar

Related Questions

#include <iostream> #include <fstream> #include <string> using namespace std; int main() { locale system();
#include <iostream> using namespace std; int main() { int a, b, c, max; cout<<a=;
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
#include <iostream> #include <tuple> int main(){ auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1 auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>()); //Line 2
#include <stdio.h> #include <iostream> #include <locale> int main() { const wchar_t *str = L\u041F\u043E\u0440\u044F\u0434\u043E\u043A;
#include <iostream> #include <cassert> #include <vector> #include <ctime> #include <cstdlib> #include <Windows.h> using namespace
#include rtest.h #include <iostream> SEXP rcpp_hello_world () { using namespace Rcpp ; CharacterVector x
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
I have the following code: #include <iostream> #include <string> #include <iomanip> #include <locale> #include
How do you find valid locale names? I am currently using MAC OS X.

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.