Menu

formating using fixed<<showpoint

2002-11-30
2012-09-26
  • Nobody/Anonymous

    I was trying to format my output by using fixed<<showpoint.  The compiler doesn't recognize this.  I have included <iomanip>.  Is there something else I shoud include.

    Thanks Kristin

     
    • Nobody/Anonymous

      Use this instead:

      cout << setiosflags(ios::fixed | ios::showpoint);

      I may be wrong, but I don't think the plain 'fixed' and 'showpoint' are standard ANSI C++.  I've seen it around, but I suspect that it may be a Microsoft corruption of the language...  Can anyone here confirm this, or else post a reference to the ANSI C++ standard about it (if it is indeed part of the standard)?

      qWake

       
    • Nobody/Anonymous

      Use this instead:

      cout << setiosflags(ios::fixed | ios::showpoint);

      I may be wrong, but I don't think the plain 'fixed' and 'showpoint' are standard ANSI C++.  I've seen it around, but I suspect that it may be a Microsoft corruption of the language...  Can anyone here confirm this, or else post a reference to the ANSI C++ standard about it (if it is indeed part of the standard)?

      qWake

       
    • Nobody/Anonymous

      qWake,

      I have mostly seen it in the form you showed it, though, to tell the truth, when I have had to control my prints, I have tended to use printf.  Its weird, but I feel more comfortable with that.

      Wayne (the weird)

       
    • Nobody/Anonymous

      Try   setf.cout (ios::fixed | ios::showpoint);

       
    • Nobody/Anonymous

      oops this is right  ...  cout.setf (ios::fixed | ios::showpoint);

       
    • Nobody/Anonymous

      This is to show use. play the the number in setprecision.
      the cout.setf(ios::fixed,ios::showpoint); sets the flag for every time you use cout  from   cout.setf(ios::fixed,ios::showpoint);   down.
       
       
       

      #include <iostream>
      #include <stdlib.h>
      #include <iomanip>

      using namespace std;

      int main()
      {
        cout.setf(ios::fixed | ios::showpoint);
        double xnan = 13.72;
        int numb;
        double num;
        numb = rand()%14307;
        num = (numb / xnan);
        cout << setprecision(6)<< num << endl;  
      system("PAUSE");
        return 0;
      }

       
    • Nobody/Anonymous

      You're not so weird Wayne, I also find printf easier to use for formatted output.  The printf formatting tokens may be more obscure to new programmers than the clearer "setprecision(2)" found in C++, but they are much more compact.

      qWake

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.