git-svn-id: https://cppannotations.svn.sourceforge.net/svnroot/cppannotations/trunk@263 f6dd340e-d3f9-0310-b409-bdd246841980
This commit is contained in:
Frank B. Brokken 2009-10-22 20:12:51 +00:00
parent 3812d933fc
commit d1d4d29feb
4 changed files with 93 additions and 100 deletions

View file

@ -53,12 +53,11 @@ includefile(iostreams/input)
lsubsect(ISTREAM)(Basic input: the class `istream')
includefile(iostreams/istream)
COMMENT( >>>>>>>>>>> NEXT <<<<<<<<<<<<<)
lsubsubsect(ISTREAMREAD)(Reading from `istream' objects)
includefile(iostreams/istreamread)
COMMENT( >>>>>>>>>>> NEXT <<<<<<<<<<<<<)
lsubsubsect(ISTREAMPOS)(`istream' positioning)
includefile(iostreams/istreamseek)

View file

@ -164,7 +164,7 @@ tt(fixed). Example:
// 3.000 3.001 3.001
)
The example shows that 3.0005 is rounded away from zero, becoming
3.001 (likewise -3.0005 becomes -3.001). First setting precision and than
3.001 (likewise -3.0005 becomes -3.001). First setting precision and then
tt(fixed) has the same effect.
)
ithtq(scientific)(ios::scientific)

View file

@ -1,13 +1,12 @@
The class ti(istream) supports both formatted and unformatted
emi(binary input). The emi(extraction operator) (ti(operator>>())) may be
The class tt(istream) supports both formatted and unformatted
emi(binary input). The emi(extraction operator) (ti(operator>>())) is
used to extract values in a i(type safe) way from tt(istream) objects. This
is called i(formatted input), whereby human-readable i(ASCII) characters are
converted, according to certain formatting rules, to binary values which are
stored in the computer's memory.
converted, according to certain formatting rules, to binary values.
Note that the extraction operator points to the objects or variables which
must receive new values. The normal associativity of rshift()
remains unaltered, so when a statement like
The extraction operator points to the objects or variables which receive new
values. The normal associativity of rshift() remains unaltered, so when a
statement like
verb(
cin >> x >> y;
)
@ -20,23 +19,22 @@ statement is reduced to
)
and the tt(y) variable is extracted from tt(cin).
The rshift() operator has various (overloaded) variants and thus many types of
The rshift() operator has many (overloaded) variants and thus many types of
variables can be extracted from tt(istream) objects. There is an overloaded
rshift() available for the extraction of an tt(int), of a tt(double), of a
string, of an array of characters, possibly to a pointer, etc. etc.. String or
character array extraction hi(string extraction) hi(extracting strings) will
(by default) skip all white space characters, and will then extract all
character array extraction hi(string extraction) hi(extracting strings)
by default first skips all white space characters, and will then extract all
consecutive non-white space characters. Once an extraction operator has been
processed the tt(istream) object from which the information was extracted is
returned and it can immediately be used for any subsequent tt(istream)
operations that follow in the same expression.
returned and it can immediately be used for additional tt(istream)
operations that appear in the same expression.
Streams do not have facilities for formatted input (like bf(C)'s
ti(scanf()) and ti(vscanf()) functions). Although it is not difficult to make
these facilities available in the world of streams, tt(scanf())-like
functionality is hardly ever required in bf(C++) programs. Furthermore, as it
is potentially type-em(unsafe), it might be better to avoid this functionality
completely.
Streams lack facilities for formatted input (as used by, e.g., bf(C)'s
ti(scanf) and ti(vscanf) functions). Although it is not difficult to add these
facilities to the world of streams, tt(scanf)-like functionality is hardly
ever required in bf(C++) programs. Furthermore, as it is potentially
type-em(unsafe), it might be better to avoid formatted input completely.
When hi(binary files) binary files must be read, the information should
normally not be formatted: an tt(int) value should be read as a series of
@ -44,85 +42,81 @@ unaltered bytes, not as a series of i(ASCII) numeric characters 0 to 9. The
following member functions for reading information from tt(istream) objects
are available:
itemization(
itht(istream::gcount())(int istream::gcount()):
quote(this function does not actually read from the input stream,
but returns the number of characters that were read from the input stream
during the last unformatted input operation.)
itht(istream::get())(int istream::get()):
quote(this function returns endOfFile() or reads and returns the
next available single character as an tt(int) value.)
itt(istream &istream::get(char &c)):
quote(this function reads the next single character from the input
stream into tt(c). As its return value is the stream itself, its return value
can be queried to determine whether the extraction succeeded or not.)
itt(istream& istream::get(char *buffer, int len [, char delim])):
quote(This function reads a series of tt(len - 1) characters from
the input stream into the array starting at tt(buffer), which should be at
least tt(len) bytes long. At most tt(len - 1) characters are read into the
buffer. By default, the delimiter is a newline (tt('\n')) character. The
delimiter itself is em(not removed) from the input stream.
ithtq(gcount)(int istream::gcount() const)
(the number of characters read from the input stream
by the last unformatted input operation is returned.)
ithtq(get)(int istream::get())
(the next available single character is returned
as an unsigned tt(char) value using an tt(int) return type.
endOfFile() is returned if no more character are available.)
itt(istream &istream::get(char &ch)):
quote(the next single character read from the input stream is
stored in tt(ch). The member function returns the stream itself which may be
inspected to determine whether a character was obtained or not.)
itt(istream& istream::get(char *buffer, int len, char delim = '\n')):
quote(At most tt(len - 1) characters are read from the input
stream into the array starting at tt(buffer), which should be at least tt(len)
bytes long. Reading also stops when the delimiter tt(delim) is
encountered. However, the delimiter itself is em(not removed) from the input
stream.
After reading the series of characters into tt(buffer), an ti(ASCII-Z)
character is written beyond the last character that was written to tt(buffer).
The functions tt(eof()) and tt(fail()) (see section
ref(IOSTATES)) return 0 (tt(false)) if the delimiter the delimiter was
encountered before reading tt(len - 1) characters or if the delimiter was not
encountered once tt(len - 1) characters were read. Furthermore, an
tt(ASCII-Z) can be used for the delimiter: this way strings terminating in
tt(ASCII-Z) characters may be read from a (binary) file. The program using
this tt(get()) member function should know in advance the maximum number of
characters that are going to be read.
Having atored the characters into tt(buffer), an ti(ASCII-Z) character is
written beyond the last character stored into the tt(buffer). The functions
tt(eof) and tt(fail) (see section ref(IOSTATES)) return 0 (tt(false)) if the
delimiter was encountered before reading tt(len - 1) characters or if the
delimiter was not encountered after reading tt(len - 1) characters.
It is OK to specifiy an tt(ASCII-Z) delimiter: this way strings
terminating in tt(ASCII-Z) characters may be read from a (binary) file.
)
itht(istream::getline())
(istream& istream::getline(char *buffer, int len [, char delim])):
quote(This function operates analogously to the previous tt(get())
member function, but tt(delim) is removed from the stream if it is
actually encountered. At most tt(len - 1) bytes are written into the
tt(buffer), and a trailing tt(ASCII-Z) character is appended to the string
that was read. The delimiter itself is em(not) stored in the tt(buffer). If
tt(delim) was em(not) found (before reading tt(len - 1) characters)
the tt(fail()) member function, and possibly also
tt(eof()) will return true. Note that the tt(std::string) class also has a
support function tt(getline()) which is used more often than this
tt(istream::getline()) member function (see section ref(STRINGMEMBERS)).)
itht(istream::ignore())
(istream& istream::ignore(int n , int delim)):
quote(This member function has two (optional) arguments. When
called without arguments, one character is skipped from the
input stream. When called with one argument, tt(n) characters are skipped. The
optional second argument specifies a delimiter: after skipping tt(n) or the
tt(delim) character (whichever comes first) the function returns.)
itht(istream::peek())(int istream::peek()):
ithtq(getline)
(istream& istream::getline(char *buffer, int len, char delim = '\n'))
(this member function operates analogously to the tt(get) member
function, but tt(getline) removes tt(delim) from the stream if it is actually
encountered. The delimiter itself, if encountered, is em(not) stored in the
tt(buffer). If tt(delim) was em(not) found (before reading tt(len - 1)
characters) the tt(fail) member function, and possibly also tt(eof) returns
true. Realize that the tt(std::string) class also offers a function
tt(std::getline) which is generally preferred over this tt(getline) member
function that is described here (see section ref(STRINGMEMBERS)).
)
ithtq(ignore)
(istream& istream::ignore())
(one character is skipped from the input stream.)
itt(istream& istream::ignore(int n)):
quote(tt(n) characters are skipped from the input stream.)
itt(istream& istream::ignore(int n, int delim)):
quote(at most tt(n) characters are skipped but skipping characters
stops after having removed tt(delim) from the input stream.)
ithtq(peek)(int istream::peek())
quote(this function returns the next available input character,
but does not actually remove the character from the input stream.)
itht(istream::putback())
(istream& istream::putback (char c)):
quote(The character tt(c) that was last read from the stream is
`pushed back' into the input stream, to be read again as the next
character. endOfFile() is returned if this is not allowed. Normally, one
character may always be put back. Note that tt(c) em(must) be the character
that was last read from the stream. Trying to put back any other character
will fail.)
itht(istream::read())
(istream& istream::read(char *buffer, int len)):
quote(This function reads at most tt(len) bytes from the input
stream into the buffer. If endOfFile() is encountered first, fewer bytes are
read, and the member function tt(eof()) will return tt(true). This function
will normally be used for reading em(binary) files. Section ref(IFSTREAM)
contains an example in which this member function is used. The member function
tt(gcount()) should be used to determine the number of characters that were
retrieved by the tt(read()) member function.
but does not actually remove the character from the input stream. endOfFile()
is returned if no more characters are available.)
ithtq(putback)(istream& istream::putback(char ch))
(The character tt(ch) is `pushed back' into the input stream, to
be read again as the next available character. endOfFile() is returned if this
is not allowed. Normally, it is OK to put back one character. Example:
verb(
string value;
cin >> value;
cin.putback('X');
// displays: X
cout << static_cast<char>(cin.get());
)
)
ithtq(read)(istream &istream::read(char *buffer, int len))
(At most tt(len) bytes are read from the input stream into the
buffer. If endOfFile() is encountered first, fewer bytes are read, with the
member function tt(eof) returning tt(true). This function is commonly used
when reading em(binary) files. Section ref(IFSTREAM) contains an example in
which this member function is used. The member function tt(gcount()) may be
used to determine the number of characters that were retrieved by tt(read).
)
ithtq(readsome)(istream& istream::readsome(char *buffer, int len))
(at most tt(len) bytes are read from the input stream into the
buffer. All available characters are read into the buffer, but if endOfFile()
is encountered, fewer bytes are read, without setting the tt(ios::eofbit)
or tt(ios::failbit).
)
itht(istream::readsome())
(istream& istream::readsome(char *buffer, int len)):
quote(This function reads at most tt(len) bytes from the input
stream into the buffer. All available characters are read into the buffer, but
if endOfFile() is encountered first, fewer bytes are
read, without setting the tt(ios_base::eofbit) or tt(ios_base::failbit).
)
itht(istream::unget())
(istream& istream::unget()):
quote(an attempt is made to push back the last character that was
read into the stream. Normally, this succeeds if requested only once after a
read operation, as is the case with tt(putback()))
ithtq(unget)(istream &istream::unget())
(the last character that was read from the stream is put back.)
)

View file

@ -6,7 +6,7 @@ a type safe way into tt(ostream) objects. This is called
memory are converted to human-readable i(ASCII) characters according to
certain formatting rules.
Note that the insertion operator points to the tt(ostream) object to
The insertion operator points to the tt(ostream) object to
receive the information. The normal associativity of lshift()
remains unaltered, so when a statement like
verb(