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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:15:21+00:00 2026-06-10T23:15:21+00:00

For the following code, is it possible to output the result to a string

  • 0

For the following code, is it possible to output the result to a string instead of wofstream? Thanks you!

wstring w = L"test";
std::wofstream ofs("test.txt");
std::locale utf8_locale(std::locale(), new boost::archive::detail::utf8_codecvt_facet());
ofs.imbue(utf8_locale);
std::copy(w.begin(),w.end(),
    std::ostream_iterator<wchar_t, wchar_t>(ofs));
  • 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-10T23:15:22+00:00Added an answer on June 10, 2026 at 11:15 pm

    Output string streams are a C++ feature that behave similarly to output file streams in the sense that they both inherit from std::ostream, meaning that you can use mostly the same functions in both. However, string streams operate on a string rather than a file.

    What this means for you is that all you need to do (as you haven’t used any wofstream-specific functions) is change the type of ofs to a string stream:

    #include <sstream>
    std::wostringstream oss;
    

    Now I couldn’t get the locale stuff building (I haven’t used those as of yet), but commenting them did indeed produce correct results (see this test). As you can see, you can access the string via the string stream’s str() function.

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

Sidebar

Related Questions

Possible Duplicate: C programming division in the following code example the result should yield
I have the following code to generate all possible substrings of a string :
Is it possible to transform following code to Linq that it will look like
How is it possible that following code even compiles? As far as I can
Suppose I have the following code to collect all the possible combinations. abArray =
I have the following code which I use to match fancybox possible elements: $('a.grouped_elements').each(function(){
In the following code, why is not possible to do this dereferencing: *arr =
Possible Duplicate: Is NULL always zero in C? Following code: char *p1 = 0;
Possible Duplicate: What do parentheses surrounding a JavaScript object/function/class declaration mean? Why following code
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in

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.