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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:43:14+00:00 2026-05-29T05:43:14+00:00

Hi I got a little question here. I am doing my C++ homework and

  • 0

Hi I got a little question here.

I am doing my C++ homework and the sample output is

% cat this.out
  5.00       0.00 
  1.55       4.76 
 -4.05       2.94 
 -4.05      -2.94 
  1.55      -4.76 

but what I got was

% cat test.out
    5       0
    1.55    4.76
    -4.05   2.94
    -4.05   -2.94
    1.55    -4.76

And I couldn’t figure out how to make my output format looks like that.
One more problem I had in this case is, I want the first line in my output is something like 5.00 0.00, but it doesn’t work even I set precision(3)

Here is my code generates the output, please take a look.

file.open (filename, fstream :: in | fstream :: trunc);
    if(!file.is_open())
    {
            cerr << "Error opening file " << filename << endl;
            cout << "Exiting..." << endl;
            exit(0);
    }
    for(i = 0 ; i < num; i ++)
    {
            angle = 2 * M_PI * i/num;
            x = rad * cos(angle);
            y = rad * sin(angle);
            file.precision(3);
            // x, y are double
            file << "\t" << x << "\t" << y << endl;
    }
    cout << "finished";
    file.close();
  • 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-29T05:43:14+00:00Added an answer on May 29, 2026 at 5:43 am

    You need to look up the Input/output manipulators in the Standard library header <iomanip>.

    These are used inline, like:

    std::cout << "\t" << std::fixed << std::setprecision(z) << x
    

    The ones you’ll be most interested in are:

    • std::fixed
    • std::setprecision
    • std::setw
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Asked the same question here but got no answer, so I'm trying here instead
Apologies for reposting but I had to edit this question when I got to
Little silly question, but got stuck for a long time. I have written two
I've got a simple question that I just KNOW won't be possible, but here
I've got another question, although I reckon this one might be a little less
i`ve got a little problem with LINQ. I read out some information via XML-RPC.
I got a little confusing situation here when I use the Context from django.template.
I got a little problem, it seems simple (personally I think it is), but
I've asked about this earlier but the question itself and all the information in
So this question is a sort of follow on from here ( how to

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.