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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:28:44+00:00 2026-05-21T02:28:44+00:00

I have a few CString variables that I wish to output to an ofstream,

  • 0

I have a few CString variables that I wish to output to an ofstream, but I can’t seem to figure out how to do so. Here’s some example code.

I have unicode enabled in VS 2005

CODE:

  ofstream ofile;
  CString str = "some text";

  ofile.open(filepath);
   ofile << str; // doesn't work, gives me some hex value such as 00C8F1D8 instead
    ofile << str.GetBuffer(str.GetLength()) << endl; // same as above
     ofile << (LPCTSTR)str << endl; // same as above

   // try copying CString to char array
  char strary[64];
  wcscpy_s(strary, str.GetBuffer()); // strary contents are correctly copied
  ofile << strary << endl ; // same hex value problem again!

Any ideas? Thanks!

  • 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-21T02:28:45+00:00Added an answer on May 21, 2026 at 2:28 am

    If you just want plain ACP encoded ANSI text:

        ofile << CT2A(str);
    

    ofstream formatted output functions expect narrow/ansi strings.

    CStrings represent TCHAR strings.

    The CT2A macro Converts TCHAR 2 Ansi.

    http://msdn.microsoft.com/en-us/libr…8VS.80%29.aspx

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

Sidebar

Related Questions

I have few 'so' files that I need to load in maven java project
I have few Vaadin tabs one of them is displaying an table and some
I have few databses of sql 2000 on windows 2000. Can I attach these
I have few values existing in data base,i need to update them but,i am
i have few variables like this: self.lamp_1 self.lamp_2 self.lamp_3 self.lamp_4 and now i want
I have few TabPages and each contains rich text box. How can I access
I have few rows in table that contain 10 co-morbidities. <table> <!-- Co-Morbidities1 -->
I have few pages that I show from my main page inside iframe .
Have few thousand reports that have consistently formatted tabular data embedded within them that
Have few short sound effect samples, which play just fine in emulator, but not

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.