🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #49717

Re: char char_tmp; if (char_tmp == 'i') {...} and setprecision(16) ???

#49717
From: Fergus Henderson
Date: Sun, 02 Jan 1994 07:26
42 lines
1913 bytes
shen@phoenix.cs.uga.edu (Mingzuo Shen) writes:

>    Question No. 2: I read a C++ book intended for Borland C++
>that there is a way to make `cout <<' print more digits for
>doubles. But the book did not give an example. When I tried
>the following, g++ says cout::setprecision is not <something>
>
>    double dtmp;
>    cout.setprecision(16);
>    cout << dtmp;
>
>So how can I get more than 6 significant digits without using
>%16f?

setprecision is an I/O manipulator, not a member function.

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

	int main(void) {
		cout << setprecision(16) << (1/3.0) << endl;
		return 0;
	}

>    Question No. 3. The same book says there is a ws manipulator.
>Does this strip white spaces from the istream? The following did
>not compile under g++:
>
>        char line_input[MAX_LINE_LENGTH];
>        cin.ws();
>        cin.getline(line_input, MAX_LINE_LENGTH);

Use the following:

	#include <iomanip.h>
	...
	cin >> ws;

-- 
Fergus Henderson        |   "People who brook no compromise in programming
                        |   languages should program in lambda calculus or
fjh@munta.cs.mu.OZ.AU   |   machine language, depending." --Andrew Koenig.
Technical Details
Message-ID: <9400218.24378@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!EU.net!howland.reston.ans.net!spool.mu.edu!sgiblab!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
References: <2fv83l$gd0@athena.cs.uga.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,1a8cec9c98a6cfdb
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1994-01-01 23:26:22 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!EU.net!howland.reston.ans.net!spool.mu.edu!sgiblab!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: char char_tmp; if (char_tmp == 'i') {...} and setprecision(16) ???
Message-ID: <9400218.24378@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU
Organization: Computer Science, University of Melbourne, Australia
References: <2fv83l$gd0@athena.cs.uga.edu>
Date: Sun, 2 Jan 1994 07:26:39 GMT
Lines: 42