I've added some advice.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
The #include files are in /usr/local/lib/g++-include:
For NUMERIC=long|int|unsigned|long unsigned,
istream
Class of input streams
Read ahead
The easiest way to read to EOF is to
attempt to input characters and test for success at the same time
while( cin >> character )because if the input fails th stream fails the test(it is (void*)0)
More complex input may need a technique know as "reading ahead":
stream >> data; // read ahead
while(stream) // repeat until end or failure
{
...//consume data
stream >> data; // replace data by next item
...
}
. . . . . . . . . ( end of section iostream.h) <<Contents | End>>
ios
This is a class that is full of special constants used to
control formatting. See the next section.
Functions that change formatting
Note: Some functions are also manipulators with different names. For example
is like
and
is like
Flags Meanings
-----------------------------------------------------------
ios::showpoint show point in whole numbers
ios::showbase Indicate Base(0,0x,...)
ios::showpos Show +sign on positive
ios::uppercase EXABCDEF not exabcdef
-----------------------------------------------------------
Setting one bit in a group of bits actually means turning off the group and then turning one the correct bit on. There is a special version of the 'setf' function that does this:
selection ios::ingroup Meaning
-----------------------------------------------------------
ios::left ios::adjustfield left alignment
ios::right ios::adjustfield right alignment
ios::internal ios::adjustfield sign on left, digits right
ios::dec ios::basefield decimals
ios::hex ios::basefield hexadecimal
ios::oct ios::basefield Octal
ios::fixed ios::floatfield fixed form of floating point
ios::scientific ios::floatfield force exponential format
-----------------------------------------------------------
However this 'setf' has no matching 'setiosflags' manipulator.
[ formats.cc ]
List of Format Flags in Library
ios::dec // use decimals
ios::fixed // no exponentials
ios::hex // use hexadecimals
ios::internal // sign on left, digits on right
ios::left // left justified
ios::oct // use octal
ios::right // right justified
ios::scientific // scientific notation
ios::showbase // Show base (hex,octal,...)
ios::showpoint // Always show a point
ios::showpos // If positive still show sign
ios::skipws // Skip whitespace on input
ios::stdio // ??
ios::unitbuf // ??
ios::uppercase // Letters in hex are UPPERCASE
ios::adjustfield = ios::left | ios::right | ios::internal.
ios::floatfield = ios::fixed | ios::scientific
ios::basefield = ios::dec | ios::hex | ios::octal
To turn on one bit in s group you can use ostream . setf(ios::bit, ios::ingroup); or ostream << resetiosflags(ios::ingroup)<<setiosflags(ios::bit)...
iomanip.h
This library automatically #includes <iostream.h>
Manipulators are used in one of two ways:
They duplicate the member functions like setf and fill.
resetiosflags( ios::fmtflags ) // reset various properties setiosflags( ios::fmtflags ) // set various properties
To turn on one bit in s group you can use ostream << resetiosflags(ios::ingroup)<<setiosflags(ios::bit)...
The setw(W) manipulator is unusual in two ways. Firstly it is the only one above that effects the next transfer only. Secondly, it is used for both istreams and ostreams.
[ giomanip.cc ]
Do-it-yourself Manipulators
Simple manipulators without arguments are very easy to define
and can make many programs easier to both read and write.
// Output manipulator example - Part 1
ostream& left(ostream& out) //set left justified
{ out.setf(ios::left, ios::adjustfield);
return out;
}
ostream& right(ostream& out) //set right justified
{ out.setf(ios::right, ios::adjustfield);
return out;
}A function that takes a reference to an istream and returns one as well can be used as an input manipulator. Similarly the name of a function that is given a ref to an ostream and returns a ref to an ostream is treated as an ostream manipulator.
// Output manipulator example - Part 2
ostream& dollars(ostream& out) //set check protected monetary formatting
{
return out << '$' << setfill('*') <<setw(10)
<< setprecision(2) << setiosflags(ios::fixed | ios:: showpoint);
}
...
cout << dollars << example << endl;
cout << left << dollars << example << endl;
cout << right << dollars << example << endl;
Setting up manipulators that have arguments is more complicated because functions that have arbitrary arguments are not recognised as iomanipulators by '<<' and '>>'. See see << and see >> above.
The technique is to define a class of objects with a constructor that has the arguments that you want that returns a function with the correct argument that has access to values of the arguments as data members of the class. Believe it or not!
The following is straight from the library....
fstreambase is used as a base for ifstream, ofstream and fstream. These are effectively the result of combining the the possibilities of handling files (fstreambase) with the matching stream class(istream, ostream, iostream respectively).
Constructors
Constructors
void open(const char *name, int mode=ios::in, int prot=0664);
Constructors
void open(const char *name, int mode=ios::out, int prot=0664) ;
Constructors
strstreambuf
Many constructors: