delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/19/14:07:52

From: roadraat AT aol DOT com (RoadRaat)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Manipulators, where are they?
Lines: 82
NNTP-Posting-Host: ladder05.news.aol.com
X-Admin: news AT aol DOT com
Date: 19 Mar 2000 17:27:14 GMT
References: <u0uads0alg6d3n3tahra4a5d5fccfpep2c AT 4ax DOT com>
Organization: AOL http://www.aol.com
Message-ID: <20000319122714.13593.00000461@ng-fm1.aol.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

>iomanip should be in djgpp/lang/cxx with the other C++ header files.
>

Thanks, Jason, for your reply.
I do have iomanip in the correct directory.  I checked to make sure, and indeed
manipulators like setprecision() and setw() work for me.

>*Please* when you report a problem make the effort to post the full
>source code to the smallest program that demonstrates the problem,
>together with the exact command line you use to compile and the full
>errors the compiler issues.  That way others will be happy to make the
>effort to find you a solution.

Hokay, here goes:  a floating point experiment...
// Program 2.6 Experimenting with floating point output
#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
 float value1 = 0.1f;
 float value2 = 2.1f;
 value1 -= 0.09f;                       // Should be 0.01
 value2 -= 2.09f;                       // Should be 0.01
 cout << setprecision(14) << fixed;     // Change to fixed notation
 cout << value1 - value2 << endl;       // Should output zero

 cout << setprecision(5) << scientific; // Return to scientific notation
 cout << value1 - value2 << endl;       // Should output zero

 return 0;
}

I compiled this with:
gpp -Wall -o 2.6a.exe 2.6a.cpp

I received the following messages:
2.6a.cpp: In function 'int main()':
2.6a.cpp: 12: 'fixed' undeclared (first use this function)
2.6a.cpp: 12: (each undeclared identifier is reported only once
2.6a.cpp: 12: for each function it appears in
(similar message regarding 'scientific')

This code is taken from Ivor Horton's Beginning C++ from Wrox.  He says that
'fixed' and 'scientific' come from iostream.  I had thought that they came from
iomanip, so I was going crazy trying to verify that I had installed everything
correctly.  I have the headers alright, but iostream doesn't seem to function
the way my textbook leads me to expect.
>
>I think this might do what you want:
>
>    cout.setf(ios::fixed, ios::floatfield);
>    cout << area << endl;
>
That suggestion is pretty close to what I want.  What I really want is the the
method setiosflags().  I fixed my code this way, beginning from my cout
statements:

 cout << setprecision(14)
      << setiosflags(ios::fixed)        // Change to fixed notation;
      << value1 - value2 << endl;       // Should output zero

 cout << setprecision(5)
      << setiosflags(ios::scientific)   // Return to scientific notation
      << value1 - value2 << endl;       // Should output zero

>> Why won't it work with DJGPP?
>
>Most likely this feature has not yet been implemented in GCC.

If that is true, then I will stop tearing out my hair presuming that I'm simply
doing something wrong.  So I can conclude the following?  DJGPP will NOT yet 
allow me to set a format just by typing 'fixed', like in my first example?  I
MUST use the old way of typing 'cout.setiosflags(ios::fixed)'?

I really began to suspect that when I started looking at the iostream file
itself, which merely forwards to iostream.h, the OLD ANSI standard.  Am I
understanding this correctly?

RoadRaat

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019