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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:23:49+00:00 2026-05-23T00:23:49+00:00

The below code is writing unreadable characters to the text file: int main ()

  • 0

The below code is writing unreadable characters to the text file:

int main () 
{
    ofstream myfile ("example.txt");

    if (myfile.is_open())
    {
        double value       = 11.23444556;
        char   *conversion = (char *)&value;
        strcat (conversion, "\0");

        myfile.write (conversion, strlen (conversion));
        myfile.close();
    }   

    return 0;
}

I want to see the actual number written in the file 🙁 Hints please.

EDIT
Seeing the answers below, I modified the code as:

int main () 
{
    ofstream myfile ("example.txt");

    if (myfile.is_open())
    {
        double value       = 11.23444556;

        myfile << value;
        myfile.close();
    }   

    return 0;
}

This produces the putput: 11.2344 while the actual number is 11.23444556. I want the complete number.

Editing the post to notify everyone:
The unreadable characters are due to ofstream’s write function:

This is an unformatted output function

This quote is from: http://www.cplusplus.com/reference/iostream/ostream/write/

  • 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-23T00:23:50+00:00Added an answer on May 23, 2026 at 12:23 am

    Why don’t you simply do this (updated answer after the edit in the question):

     #include <iomanip>
    
     myfile << std::fixed << std::setprecision(8) << value;
     myfile.close();
    

    Now, you can see the actual number written in the file.

    See the documentation of std::setprecision. Note: you have to include the <iomanip> header file.

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

Sidebar

Related Questions

am writing a java code that needs to save a file. the below code
I'm writing code to do Xml serialization. With below function. public static string SerializeToXml(object
Writing the code below without dot notation, do I have this right? from: if(self.yellowViewController.view.superview
When running the below code a type is never returned, despite there being a
In the below code snippet can i replace char * to const char *
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD
In the below code sample, what does {0:X2} mean? This is from the reflection
In the below code, the ListBox gets filled with the names of the colors
I would like to know how to modify the below code to strip =20
When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should

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.