home *** CD-ROM | disk | FTP | other *** search
Wrap
Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
═══ 1. Chapter 1. Introduction ═══ This book describes the basic class libraries included with the &IBMcxxcomp. These class libraries provide sets of predefined classes that you can use to perform common functions such as input and output or complex arithmetic. The following information is contained in this chapter: o What are the class libraries? o Who should use this book o How to use this book o A note about examples o Related documentation You can also go back to the table of contents. ═══ 1.1. What Class Libraries Are Described in this Book? ═══ A C++ class library is a collection of related classes and functions. This book describes these three basic class libraries: o The Complex Mathematics Library o The I/O Stream Library o The Task Library. See Chapter 2, -- Reference h000175 not found -- for a brief description of the contents of these libraries. ═══ 1.2. Who Should Use This Book ═══ This book is designed as a reference for people who are familiar with the C++ language in general, and with the characteristics of C++ classes in particular. This book should help you to use the class libraries that are included with the &cxxcompl.. ═══ 1.3. How to Use This Book ═══ This book has three parts that correspond to the three basic class libraries. Part 2, Chapters 3 - 6, describes the Complex Mathematics Library. Part 3, Chapters 6 - 18, describes the I/O Stream Library. Part 4, Chapters 19 - 23, describes the Task Library. Each of these three parts can be read independently. If you need information about the I/O Stream Library, begin by reading Chapter 6. It contains important information about the organization of the I/O Stream Library, as well as some essential definitions. This chapter is especially important for you if you are familiar with the AT&T** or UNIX** System Laboratories C++ Language System Iostream Library. New terms are defined in Chapter 6 to describe certain aspects of the I/O Stream Library. These terms are not used in the corresponding AT&T documentation for the Iostream Library. ═══ 1.3.1. Organization of Chapters ═══ o Part 1. General Information - Chapter 1, "Introduction"(the chapter you are reading now) describes the organization of the book and how to use it. - Chapter 2, "What are the Class Libraries?" introduces the three basic class libraries that are described in this book. o Part 2. The Complex Mathematics Library - Chapter 3, "Introduction to the Complex Mathematics Library" lists the classes that make up the Complex Mathematics Library and provides a brief review of complex arithmetic. - Chapter 4, "complex Class" describes complex, the class that lets you manipulate complex numbers. - Chapter 5, "c_exception Class" describes c_exception, the class that provides run-time error-handling facilities for the Complex Mathematics Library. - Chapter 5, "c_exception Class" describes c_exception, the class that provides run-time error-handling facilities for the Complex Mathematics Library. o Part 3. The I/O Stream Library - Chapter 6, "Introduction to the I/O Stream Library" introduces the I/O Stream Library. It lists the classes that make up the I/O Stream Library and the header files that contain their declarations. It also describes the key concept of stream buffers. - Chapter 7, "streambuf Protected Interface" describes those members of the streambuf class that you need to know about to create your own classes derived from streambuf. This part of the streambuf class is called the protected interface. - Chapter 8, "streambuf Public Interface" describes those members of the streambuf class that you can use directly to manipulate an object of filebuf, stdiobuf, or strstreambuf, the predefined classes that are derived from streambuf. This part of the streambuf class is called the public interface. - Chapter 9, "ios Class" describes ios, the base class for the classes that format data that comes from the stream buffer. - Chapter 10, "istream and istream_withassign Classes" describes istream, the class that lets you extract data from a stream buffer. This chapter also describes istream_withassign, a class derived from istream that includes an assignment operator. - Chapter 11, "ostream and ostream_withassign Classes" describes ostream, the classes that let you insert data into a stream buffer. This chapter also describes ostream_withassign, a class derived from ostream that includes an assignment operator. - Chapter 12,"iostream and iostream_withassign Classes" describes iostream, the class that is derived from istream and ostream, and iostream_withassign, the class that is derived from istream_withassign and ostream_withassign. - Chapter 13, "filebuf Class" describes filebuf, the class that specializes streambuf to use files. - Chapter 14, "fstream, ifstream, and ofstream Classes" describes fstream, ifstream, and ofstream, the classes that adapt istream, ostream, and iostream, respectively, to use files. - Chapter 15, "strstreambuf Class" describes strstreambuf, the class that specializes streambuf to use an array of bytes in memory as the source or target of data. - Chapter 16, "strstream, istrstream, and ostrstream Classes" describes istrstream, ostrstream, and strstream, the classes that adapt istream, ostream, and iostream, respectively, to use an array of bytes in memory as the source or target of data. - Chapter 17, "stdiobuf and stdiostream Classes" describes stdiobuf, the class that lets you mix standard C input and output functions with the C++ I/O Stream Library input and output functions. - Chapter 18, "Manipulators" describes the manipulators that allow you to use the input operator or the output operator to change the state of the stream that is being used as the source or target of data. o Part 4. The Task Library - Chapter 19, "Introduction to the Task Library" gives an overview of the Task Library and lists the run-time error messages generated by the Task Library. - Chapter 20, "Task Handling Classes" describes object, sched, task, and timer, the task handling classes. These classes give you the facilities to create and manage tasks. - Chapter 21, "Queue Management Classes" describes qhead and qtail, the queue management classes. These classes let you implement a wide range of message-passing and data-buffering schemes. - Chapter 22, "Interrupt_handler Class" describes Interrupt_handler, the class that allows your tasks to handle external events in the form of signals from the operating system. - Chapter 23, "Simulation Classes"describes histogram, randint, urand, and erand, the simulation classes. These classes provide utilities for writing program simulations and gathering statistics about them. o Part 5. Appendices, Glossary, and Index - Appendix A, "Table of Functions" lists all of the functions described in this book, along with their class and library, and references to the section of the book that describes them. - Appendix B, "Extended Complex Mathematics Library Examples" contains an examples of how to determine the roots of a complex number and how to define your own complex_error function. - Appendix C, "Extended Task Library Examples" contains examples of how to use the Task Library to implement a parallel algorithm and an event-driven simulation. ═══ 1.3.2. Organization of Class Descriptions ═══ The chapters that contain detailed descriptions of classes (Chapters 4 - 5, Chapters 7 - 18, and Chapters 20 - 23) have the following format: o An introduction to the classes being described. o A discussion of how to use the classes, if appropriate. o An excerpt from the appropriate header files that shows the relevant declarations for the classes being described. These excerpts are supposed to act as supplements to the member function descriptions. They are not complete listings of the header files. If you need to know the value of an element in an enumeration, or any other specific detail about the declaration of a class, you should look at the header file itself. o A description of each member function of each class that the chapter describes. For each class, this begins with a description of the constructor and destructor, if they exist. Descriptions of the remaining members follow in alphabetical order. For the more complicated classes, like streambuf, the descriptions of members with related operations are grouped together. In most classes, only public and protected members are described. Private members are only described if they are needed to describe a public member. In addition, none of the inherited members in a derived class is described in the discussion of that class, except for virtual functions that do not use the inherited function definition. ═══ 1.3.3. How to Find the Description of a Particular Function ═══ The organization of the class libraries can be difficult to understand. The I/O Stream Library, especially, has a complicated hierarchy of classes. A function may be defined in more than one class, and it may be overloaded in a single class. Function name overloading gives C++ many advantages, but it also makes it difficult to describe the functions in a simple, linear fashion. If you know the class in which a function is defined, you can go directly to the chapter where that class is described. There, the functions are grouped according to their purpose and listed alphabetically within each group. If a class has more than one version of a function, all of the versions are described in one section. ═══ 1.3.4. Fonts Used in This Book ═══ In this book, C++ code and code fragments appear in special font. Uninstantiated variables appear in italics. ═══ 1.4. A Note about Examples ═══ The examples in this book explain elements of the C++ class libraries. They are coded in a simple style. They do not try to conserve storage, check for errors, achieve fast run times, or demonstrate all possible uses of a language element. ═══ 1.5. Related Documentation ═══ You might want to refer to the following publications for additional information: IBM Publications: &BLcxxlr., &dnlr., describes the &cpp. language. The following is a sample of some non-IBM C++ publications that are generally available. It is not an exhaustive list. IBM does not specifically recommend any of these books, and other C++ publications may be available in your locality. The Annotated C++ Reference Manual by Margaret A. Ellis and Bjarne Stroustrup, Addison-Wesley Publishing Company. The C++ Programming Language (Second Edition) by Bjarne Stroustrup, Addison-Wesley Publishing Company. C:super.++:esuper. Primer (Second Edition) by Stanley B. Lippman, Addison-Wesley Publishing Company. ═══ 2. Chapter 2. What Are the Class Libraries? ═══ This chapter introduces the three class libraries that are described in this book: o The Complex Mathematics Library provides you with the facilities to manipulate complex numbers and perform standard mathematical operations on them. o The I/O Stream Library (also known as the Iostream Library, see -- Reference h000175 not found --) provides you with the facilities to deal with many varieties of input and output. You can derive classes from this library to customize the input and output facilities for your own particular needs. o The Task Library provides you with the facilities to write programs that are made up of tasks. Tasks are lightweight (that is, they require fewer CPU resources than standard &opsysabbr. processes) and are nonpreemptive. The Task Library follows the coroutine paradigm. The following topics are described in this chapter: o History of the class libraries o Compiling and linking programs that use class libraries o Other class libraries You can also go back to the table of contents. ═══ 2.1. Other Class Libraries ═══ In addition to the three standard class libraries, &opcxx. also supports the the Building Blocks Library. This library provides you with the facilities to create objects of common data structures such as linked lists and various kinds of trees. See the &BSbb. for details about this class library. ═══ 3. Chapter 3. Introduction to the Complex Mathematics Library ═══ This chapter introduces the Complex Mathematics Library. Appendix B, "Extended Complex Mathematics Library Examples" contains examples of how you might use the Complex Mathematics Library. The following topics are described in this chapter: o Overview of the Complex Mathematics Library o Review of complex numbers You can also go back to the table of contents. ═══ 3.1. Overview of the Complex Mathematics Library ═══ The Complex Mathematics Library is made up of two classes: o complex, the class that gives you the facilities to manipulate complex numbers and perform the standard mathematical operations on them. o cexception, the class that lets you handle run-time errors that are created by the functions and operations in the complex class. ═══ 3.2. Review of Complex Numbers ═══ A complex number is made up of two parts: a real part and an imaginary part. A complex number can be represented by an ordered pair (a, b ), where a is the value of the real part of the number and b is the value of the imaginary part. If ( a, b ) and ( c, d ) are imaginary numbers, then the following statements are true: o ( a, b ) + ( c, d ) = ( a + c, b + d ) o (a, b ) - ( c, d ) = ( a - c, b - d ) o ( a, b ) * ( c, d ) = ( ac - bd, ad + bc ) o ( a, b ) / ( c, d ) = ( ( ac + bd ) / ( c [2 ]+ d [2 ]), ( bc - ad ) / ( c [2] + d [2 ]) ) o The conjugate of a complex number ( a, b ) is ( a, - b ). o The absolute value or magnitude of a complex number ( a, b ) is the positive square root of the value a [2] + b [2]. o The polar representation of ( a, b ) is ( r, theta ), where r is the distance from the origin to the point ( a, b ) in the complex plane, and theta is the angle from the real axis to the vector ( a, b ) in the complex plane. The angle theta can be positive or negative. "Figure: Polar Representation of Complex Number ( a, b )" illustrates the polar representation ( r, theta ) of the complex number ( a, b ). ArtworkfromInterleafneedstoberedrawnorincluded from an encapsulated poststript file. Polar Representation of Complex Number ( a, b ) ═══ 4. Chapter 4. complex Class ═══ This chapter describes complex, the class that provides you with the facilities to manipulate complex numbers. The following topics are described in this chapter: o Declarations for the complex class in the &complexH. header file o Complex constructors o Complex mathematical operators o Complex input and output operators o Complex mathematical functions o Complex trigonometric functions o Complex magnitude o Complex conversions You can also go back to the table of contents. ═══ 4.1. Declarations for complex in the complex.h Header File ═══ You must include the following statement in any file that uses the complex class: #include <complex.h> The following is an excerpt from the &complexH. header file that shows the relevant declarations for the member functions of the complex class: #include <iostream.h> #include <errno.h> #include <math.h> #define DOMAIN 1 #define SING 2 #define OVERFLOW 3 #define UNDERFLOW 4 #define M_E 2.7182818284590452354 #define M_LOG2E 1.4426950408889634074 #define M_LOG10E 0.43429448190325182765 #define M_LN2 0.69314718055994530942 #define M_LN10 2.30258509299404568402 #define M_PI 3.14159265358979323846 #define M_PI_2 1.57079632679489661923 #define M_PI_4 0.78539816339744830962 #define M_1_PI 0.31830988618379067154 #define M_2_PI 0.63661977236758134308 #define M_2_SQRTPI 1.12837916709551257390 #define M_SQRT2 1.41421356237309504880 #define M_SQRT1_2 0.70710678118654752440 class complex { double re, im; public: complex(); complex(double r, double i = 0.0); friend double real(const complex&); friend double imag(const complex&); friend double abs(complex); friend double norm(complex); friend double arg(complex); friend complex conj(complex); friend complex cos(complex); friend complex cosh(complex); friend complex exp(complex); friend complex log(complex); friend complex pow(double, complex); friend complex pow(complex, int); friend complex pow(complex, double); friend complex pow(complex, complex); friend complex polar(double, double = 0); friend complex sin(complex); friend complex sinh(complex); friend complex sqrt(complex); friend complex operator+(complex, complex); friend complex operator-(complex); friend complex operator-(complex, complex); friend complex operator*(complex, complex); friend complex operator/(complex, complex); friend int operator==(complex, complex); friend int operator!=(complex, complex); void operator+=(complex); void operator-=(complex); void operator*=(complex); void operator/=(complex); }; istream& operator>>(istream&, complex&); ostream& operator<<(ostream&, complex); extern const complex complex_zero(0,0); extern int errno; Note: This header file excerpt, and all of the other header file excerpts in this book, are unpublished proprietary source code of AT&T and UNIX System Laboratories. &copr. Copyright 1991 AT&T and UNIX System Laboratories, Inc. &copr. Copyright 1984, 1989, 1990 AT&T. All rights reserved. ═══ 4.1.1. Constants Defined in complex.h ═══ The following table lists the mathematical constants that the Complex Mathematics Library defines (if they have not been previously defined): ┌───────────────────────────────────────────────────────┐ │ Constants Defined in complex.h │ ├──────────────────────┬────────────────────────────────┤ │ CONSTANT NAME │ DESCRIPTION │ ├──────────────────────┼────────────────────────────────┤ │ M_E │ The constant e │ ├──────────────────────┼────────────────────────────────┤ │ M_LOG2E │ The logarithm of e to the base │ │ │ of 2 │ ├──────────────────────┼────────────────────────────────┤ │ M_LOG10E │ The logarithm of e to the base │ │ │ of 10 │ ├──────────────────────┼────────────────────────────────┤ │ M_LN_2 │ The natural logarithm of 2 │ ├──────────────────────┼────────────────────────────────┤ │ M_LN10 │ The natural logarithm of 10 │ ├──────────────────────┼────────────────────────────────┤ │ M_PI │ у │ ├──────────────────────┼────────────────────────────────┤ │ M_PI_2 │ у / 2 │ ├──────────────────────┼────────────────────────────────┤ │ M_PI_4 │ у / 4 │ ├──────────────────────┼────────────────────────────────┤ │ M_1_PI │ 1 / у │ ├──────────────────────┼────────────────────────────────┤ │ M_2_PI │ 2 / у │ ├──────────────────────┼────────────────────────────────┤ │ M_2_SQRTPI │ 2 divided by the square root │ │ │ of у │ ├──────────────────────┼────────────────────────────────┤ │ M_SQRT2 │ The square root of 2 │ ├──────────────────────┼────────────────────────────────┤ │ M_SQRT1_2 │ The square root of 1 / 2 │ └──────────────────────┴────────────────────────────────┘ ═══ 4.2. Constructors for complex ═══ There are two versions of the complex constructor: complex(); complex(double r, double i=0.0); If you declare a complex object without specifying any values for the real or imaginary part of the complex value, the constructor that takes no arguments is used and the complex value is initialized to (0, 0). For example, the following declaration gives the object comp the value (0, 0): complex comp; If you give either one or two values in your declaration, the constructor that takes two arguments is used. If you only give one value, the real part of the complex object is initialized to that value, and the imaginary part is initialized to 0. For example, the following declaration gives the object comp2 the value (3.14, 0): complex comp2(3.14); If you give two values in the declaration, the real part of the complex object is initialized to the first value and the imaginary part is initialized to the second value. For example, the following declaration gives the object comp3 the value (3.14, 6.44): complex comp3(3.14, 6.44); There is no explicit complex destructor. ═══ 4.2.1. Using the Complex Constructor to Initialize Arrays ═══ You can use the complex constructor to initialize arrays of complex numbers. If the list of initial values is made up of complex values, each array element is initialized to the corresponding value in the list of initial values. However, if the list of initial values is not made up of complex values, the real parts of the array elements are initialized to these initial values and the imaginary parts of the array elements are initialized to 0. In the following example, the elements of array b are initialized to the values in the initial value list, but only the real parts of elements of array a are initialized to the values in the initial value list. #include <complex.h> void main() { complex a[3] = {1.0, 2.0, 3.0}; complex b[3] = {complex(1.0, 1.0), complex(2.0, 2.0), complex(3.0, 3.0)}; cout << "Here is the first element of a: " << a[0] << endl; cout << "Here is the first element of b: " << b[0] << endl; } This example produces the following output: Here is the first element of a: ( 1, 0) Here is the first element of b: ( 1, 1) ═══ 4.3. Mathematical Operators for complex ═══ The complex operators described in this section have the same precedence as the corresponding real operators. ═══ 4.3.1. Addition ═══ friend complex operator+(complex x, complex y); The addition operator returns the sum of x and y. ═══ 4.3.2. Subtraction ═══ friend complex operator-(complex x, complex y); The subtraction operator returns the difference between x and y. ═══ 4.3.3. Negation ═══ friend complex operator-(complex x); The negation operator returns (- a, - b) when its argument is (a, b). ═══ 4.3.4. Multiplication ═══ friend complex operator*(complex x, complex y) The multiplication operator returns the product of x and y. ═══ 4.3.5. Division ═══ friend complex operator/(complex x, complex y) The division operator returns the quotient of x divided by y. ═══ 4.3.6. Equality ═══ friend int operator==(complex x, complex y); The equality operator "==" returns a nonzero value if x equals y. This operator tests for equality by testing that the two real components are equal and that the two imaginary components are equal. Because both components are double values, the operator should really test for an absolute difference (within a certain tolerance) between the two pairs of corresponding components. See "Inequality" below for an example of a function that performs such a test. ═══ 4.3.7. Inequality ═══ friend int operator!=(complex x, complex y); The inequality operator "! =" returns a nonzero value if x does not equal y. This operator tests for inequality by testing that the two real components are not equal and that the two imaginary components are not equal. Because both components are double values, the operator should really test for an absolute difference (within a certain tolerance) between the two pairs of corresponding components. In the following example, the functions is_equal and is_not_equal are defined to test whether two complex values are equal or not equal, respectively, within a certain tolerance. You should use functions like is_equal and is_not_equal, rather than the equality and inequality operators, if you want a reliable comparison between two complex values. #include <complex.h> int is_equal(const complex &a, const complex &b, const double tol=0.0001) { return (abs(real(a) - real(b)) < tol && abs(imag(a) - imag(b)) < tol); } int is_not_equal(const complex &a, const complex &b, const double tol=0.0001) { return !is_equal(a, b, tol); } void main() { complex c1 = complex(1.0, 2.0); complex c2 = c1; complex c3 = complex(3.0, 4.0); if (is_equal(c1, c2)) cout << "c1 is equal to c2" << endl; else cout << "c1 is not equal to c2 - not possible!" << endl; if (is_not_equal(c1, c3)) cout << "c1 is not equal to c3" << endl; else cout << "c1 is equal to c3 - not possible!" << endl; } This example produces the following output: c1 is equal to c2 c1 is not equal to c3 ═══ 4.3.8. Mathematical Assignment Operators ═══ void operator+=(complex x); void operator-=(complex x); void operator*=(complex x); void operator/=(complex x); The following list describes the functions of the mathematical assignment operators: o x + = y assigns the value of x + y to x. o x - = y assigns the value of x - y to x. o x * = y assigns the value of x * y to x. o x / = y assigns the value of x / y to x. Note: The assignment operators do not produce a value that can be used in an expression. The following code, for example, produces a compile-time error: complex x, y, z; // valid declaration x = (y += z); // invalid assignment causes a // compile-time error ═══ 4.3.9. Example ═══ The following example shows how you can use the complex mathematical operators: #include <complex.h> void main() { complex a, b; cout << "enter two complex values" << endl; cin >> a >> b; cout << "The sum of these two numbers is " << a+b << endl; cout << "The difference between these two numbers is " << a-b << endl; cout << "The product of these two numbers is " << a*b << endl; cout << "The first number divided by the second is " << a/b << endl; } If you run this program with the values ( 1, 1 ) and ( 2, 2 ) for input, the output will look like this: enter two complex values The sum of these two numbers is ( 3, 3) The difference between these two numbers is ( -1, -1) The product of these two numbers is ( 0, 4) The first number divided by the second is ( 0.5, 0) ═══ 4.4. Input and Output Operators for complex ═══ ═══ 4.4.1. Input Operator ═══ istream& operator>>(istream& is, complex& c); The input (or extraction) operator >> takes complex value c from the stream is in the form ( a, b ). The parentheses and comma are mandatory delimiters for input when the imaginary part of the complex number being read is nonzero. Otherwise, they are optional. In both cases, whitespace is optional. ═══ 4.4.2. Output Operator ═══ ostream& operator<<(ostream& os, complex c); The output (or insertion) operator << writes complex value c to the stream os in the form ( a, b ). ═══ 4.4.3. Example ═══ #include <complex.h> void main(){ complex x; cout << "Enter a complex number in the form (a,b):" << endl; cin >> x; cout << "Here is the complex value: " << x << endl; // } This example produces the following output if you enter the complex value ( 3, 4 ) at the prompt: Enter a complex number in the form (a,b): Here is the complex value: (3,4) ═══ 4.5. Mathematical Functions for complex ═══ ═══ 4.5.1. exp - Exponent ═══ friend complex exp(complex x); exp() returns the complex value equal to e [x] where x is the argument. The table in Results of the Default Error-Handling Procedures shows the values returned by the default error-handling procedure for exp(). ═══ 4.5.2. log - Logarithm ═══ friend complex log(complex x); log() returns the natural logarithm of the argument x. The table in Results of the Default Error-Handling Procedures shows the values returned by the default error-handling procedure for log(). ═══ 4.5.3. pow - Power ═══ friend complex pow(double d, complex z); friend complex pow(complex c, int i); friend complex pow(complex c, double d); friend complex pow(complex c, complex z); pow() returns the complex value x[y], where x is the first argument and y is the second argument. pow() is overloaded four times. If d is a double value, i is an integer value, and c and z are complex values, then pow() can produce any of the following results: o d[z] o c[i] o c[d] o c[z] ═══ 4.5.4. sqrt - Square Root ═══ friend complex sqrt(complex x) sqrt() returns the square root of its argument. If c and d are real values, then every complex number ( a, b ), where: o a = c[2] - d[2] o b = 2cd has two square roots: o ( c, d ) o ( - c, - d ) sqrt() returns the square root that has a positive real part, that is, the square root that is contained in the first or fourth quadrants of the complex plane. ═══ 4.5.5. Example ═══ The following program shows how you can use the complex mathematical functions: #include <complex.h> void main() { complex a, b; int i; double f; // // prompt the user for an argument for calls to // exp(), log(), and sqrt() // cout << "Enter a complex value" << endl; cin >> a; cout << "The value of exp() for " << a << " is: " << exp(a) << endl; cout << "The natural logarithm of " << a << " is: " << log(a) << endl; cout << "The square root of " << a << " is: " << sqrt(a) << endl << endl; // // prompt the user for arguments for calls to pow() // cout << "Enter 2 complex values (a and b), an integer (i),"; cout << " and a floating point value (f)" << endl; cin >> a >> b >> i >> f; cout << "a is " << a << ", b is " << b << ", i is " << i; cout << ", f is " << f << endl; cout << "The value of f**a is: " << pow(f, a) << endl; cout << "The value of a**i is: " << pow(a, i) << endl; cout << "The value of a**f is: " << pow(a, f) << endl; cout << "The value of a**b is: " << pow(a, b) << endl; } This program produces the following output when you give it ( 1,1 ), ( 1,1 ), ( 1,0 ), 1, and 1.0 as input: Enter a complex value The value of exp() for ( 1, 1) is: ( 1.46869, 2.28736) The natural logarithm of ( 1, 1) is: ( 0.346574, 0.785398) The square root of ( 1, 1) is: ( 1.09868, 0.45509) Enter 2 complex values (a and b), an integer (i), and a floating point value (f) a is ( 1, 1), b is ( 1, 0), i is 1, f is 1 The value of f**a is: ( 1, 0) The value of a**i is: ( 1, 1) The value of a**f is: ( 1, 1) The value of a**b is: ( 1, 1) ═══ 4.6. Trigonometric Functions for complex ═══ ═══ 4.6.1. cos - Cosine ═══ friend complex cos(complex x); cos() returns the cosine of x. ═══ 4.6.2. cosh - Hyperbolic Cosine ═══ friend complex cosh(complex x); cosh() returns the hyperbolic cosine of x. The table in Results of the Default Error-Handling Procedures shows the values returned by the default error-handling procedure for cosh(). ═══ 4.6.3. sin - Sine ═══ friend complex sin(complex x); sin() returns the sine of x. ═══ 4.6.4. sinh - Hyperbolic Sine ═══ friend complex sinh(complex x); sinh() returns the hyperbolic sine of x. The table in Results of the Default Error-Handling Procedures shows the values returned by the default error-handling procedure for sinh(). ═══ 4.6.5. Example ═══ The following example shows how you can use the complex trigonometric functions: #include <complex.h> void main() { complex a = (M_PI, M_PI_2); // a = (pi,pi/2) // // display the values of cos(), cosh(), sin(), and sinh() // for (pi,pi/2) // cout << "The value of cos() for (pi,pi/2) is: " << cos(a) << endl; cout << "The value of cosh() for (pi,pi/2) is: " << cosh(a) << endl; cout << "The value of sin() for (pi,pi/2) is: " << sin(a) << endl; cout << "The value of sinh() for (pi,pi/2) is: " << sinh(a) << endl; } This program produces the following output: The value of cos() for (pi,pi/2) is: ( 6.12323e-17, 0) The value of cosh() for (pi,pi/2) is: ( 2.50918, 0) The value of sin() for (pi,pi/2) is: ( 1, -0) The value of sinh() for (pi,pi/2) is: ( 2.3013, 0) ═══ 4.7. Magnitude Functions for complex ═══ ═══ 4.7.1. abs - Absolute Value ═══ friend double abs(complex x); abs() returns the absolute value or magnitude of its argument. The absolute value of a complex value ( a, b ) is the positive square root of a [2] + b [2]. ═══ 4.7.2. norm - Square Magnitude ═══ friend double norm(complex x); norm() returns the square of the magnitude of its argument. If the argument x is equal to the complex number ( a, b ), norm() returns the value a [2]+b [2]. norm() is faster than abs(), but it is more likely to cause overflow errors. ═══ 4.8. Conversion Functions for complex ═══ The conversion functions in the Complex Mathematics Library allow you to convert between the polar and standard complex representations of a value and to extract the real and imaginary parts of a complex value. ═══ 4.8.1. arg - Angle in Radians ═══ friend double arg(complex x); arg() returns the angle (in radians) of the polar representation of its argument. If the argument x is equal to the complex number ( a, b ), the angle returned is the angle in radians on the complex plane between the real axis and the vector ( a, b ). The return value has a range of -p to p. See -- Reference UAF1d0mrya. not found -- for an illustration of the polar representation of complex numbers. ═══ 4.8.2. conj - Conjugation ═══ friend complex conj(complex x); conj() returns the complex value equal to ( a, - b ) if the input argument x is equal to ( a, b ). ═══ 4.8.3. polar - Polar to Complex ═══ friend complex polar(double a, double b = 0); polar() returns the standard complex representation of the complex number that has a polar representation ( a, b ). ═══ 4.8.4. real - Extract Real Part ═══ friend double real(const complex& x); real() extracts the real part of the complex number x. ═══ 4.8.5. imag - Extract Imaginary Part ═══ friend double imag(const complex& x); imag() extracts the imaginary part of the complex number x. ═══ 4.8.6. Example ═══ The following program shows how you can use the complex conversion functions: #include <complex.h> void main() { complex a; // // for a value supplied by the user, display the real part, // the imaginary part, and the polar representation // cout << "enter a complex value" << endl; cin >> a; cout << "the real part of this value is " << real(a) << endl; cout << "the imaginary part of this value is " << imag(a) << endl; cout << "the polar representation of this value is " << "(" << abs(a) << "," << arg(a) << ")" << endl; } This program produces the following output when you give it ( 1,1 ) as input: enter a complex value the real part of this value is 1 the imaginary part of this value is 1 the polar representation of this value is (1.41421,0.785398) ═══ 5. Chapter 5. c_exception Class ═══ This chapter describes c_exception, the class that lets you handle errors that are created by the functions and operations in the complex class. The following topics are described in this chapter: o Declarations for cexception in the &complexH. header file o Constructor for cexception o Data members of cexception o Errors handled by the Complex Mathematics Library o Errors handled outside of the Complex Mathematics Library You can also go back to the table of contents. ═══ 5.1. Declarations for c_exception in the complex.h Header File ═══ You must include the following statement in any file that uses members of the c_exception class: #include <complex.h> The following is an excerpt from the &complexH. header file that shows the relevant declarations for the members of cexception: #define DOMAIN 1 #define SING 2 #define OVERFLOW 3 #define UNDERFLOW 4 extern int errno; class c_exception { int type; char *name; complex arg1; complex arg2; complex retval; public: c_exception( char *n, const complex& a1, const complex& a2 = complex_zero) friend int complex_error( c_exception& ); friend complex exp( complex ); friend complex sinh( complex ); friend complex cosh( complex ); friend complex log( complex ); }; ═══ 5.2. Constructor for c_exception ═══ c_exception(char *n, const complex& a1, const complex& a2 = complex_zero); The cexception constructor creates a cexception object with name member equal to n, arg1 member equal to a1, and arg2 member equal to a2. ═══ 5.3. Data Members of c_exception ═══ ═══ 5.3.1. arg1, arg2 - Arguments of the Function that Caused the Error ═══ complex arg1; complex arg2; arg1 and arg2 are the arguments with which the function that caused the error was called. ═══ 5.3.2. name - Name of the Function that Caused the Error ═══ char *name; name is a string that contains the name of the function where the error occurred. ═══ 5.3.3. retval - Value Returned by the Default Definition of the Error Handling Function ═══ complex retval; retval is the value that the default definition of the error handling function complex_error() returns. You can make your own definition of complex_error() return a different value. ═══ 5.3.4. type - Type of Error that Has Occurred ═══ int type; type describes the type of error that has occurred. It can take the following values that are defined in the &complexH. header file: o SING argument singularity o OVERFLOW overflow range error o UNDERFLOW underflow range error. ═══ 5.4. Errors Handled by the Complex Mathematics Library ═══ ═══ 5.4.1. complex_error - the Error-Handling Function ═══ friend int complex_error(c_exception& ce); complex_error() is invoked by member functions of the Complex Mathematics Library when errors are detected. The argument ce refers to the cexception object that contains information about the error. You can define your own procedures for handling errors by defining a function called complex_error with return type int and a single parameter of type c_exception&. If you define your own complex_error function and this function returns a nonzero value, no error message will be generated and the external variable errno will not be set. If this function returns zero, errno is given the value of one of the following constants: o ERANGE if the result is too large or too small o EDOM if there is a domain error within a mathematical function. These constants are defined in &errnoH.. ═══ 5.4.2. Results of the Default Error-Handling Procedures ═══ If you do not define your own complex_error, the default error-handling procedures will be invoked when an error occurs. The results for a given input complex value (a, b) depend on the kind of error and the sign of the cosine and sine of b. The following table shows the return value of the default error-handling procedure and the value given to errno for each function with input equal to the complex value (a, b). The following symbols appear in this table: 1. NA - not applicable. The result of the error depends on the sign of the cosine and sine of b (the imaginary part of the argument) unless "NA" appears in the Cosine b or Sine b columns. 2. HUGE - the maximum double value. This value is defined in the header file math.h. ┌────────────────────────────────────────────────────────────────┐ │ Results of the Default Error-Handling Procedures │ ├─────┬────────┬─────────┬─────────┬─────────────┬───────────────┤ │ Func│iError │ Cosine │ Sine b │ Return │ errno Value │ │ │ │ b │ │ Value │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ cosh│ a too │ nonneg- │ nonneg- │ ("┼HUGE,┼HUG│""ERANGE" │ │ │ large │ ative │ ative │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ cosh│ a too │ nonneg- │ nega- │ ("┼HUGE,-HUG│""ERANGE" │ │ │ large │ ative │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ cosh│ a too │ nonneg- │ nonneg- │ ("┼HUGE,-HUG│""ERANGE" │ │ │ small │ ative │ ative │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ cosh│ a too │ nonneg- │ nega- │ ("┼HUGE,┼HUG│""ERANGE" │ │ │ small │ ative │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ cosh│ a too │ nega- │ nonneg- │ ("-HUGE,-HUG│""ERANGE" │ │ │ small │ tive │ ative │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ cosh│ a too │ nega- │ nega- │ ("-HUGE,┼HUG│""ERANGE" │ │ │ small │ tive │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ cosh│ b too │ nega- │ nonneg- │ ("-HUGE,┼HUG│""ERANGE" │ │ │ large │ tive │ ative │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ cosh│ b too │ nega- │ nega- │ ("-HUGE,-HUG│""ERANGE" │ │ │ large │ tive │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ cosh│ b too │ NA │ NA │ (0,0) │ "ERANGE" │ │ │ small │ │ │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ exp │ a too │ posi- │ posi- │ ("┼HUGE,┼HUG│""ERANGE" │ │ │ large │ tive │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ exp │ a too │ posi- │ nonpos- │ ("┼HUGE,-HUG│""ERANGE" │ │ │ large │ tive │ itive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ exp │ a too │ nonpos- │ posi- │ ("-HUGE,┼HUG│""ERANGE" │ │ │ large │ itive │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ exp │ a too │ nonpos- │ nonpos- │ ("-HUGE,-HUG│""ERANGE" │ │ │ large │ itive │ itive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ exp │ a too │ NA │ NA │ ("0,0") │ "ERANGE" │ │ │ small │ │ │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ exp │ b too │ NA │ NA │ ("0,0") │ "ERANGE" │ │ │ large │ │ │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ exp │ b too │ NA │ NA │ ("0,0") │ "ERANGE" │ │ │ small │ │ │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ log │ a too │ posi- │ posi- │ ("┼HUGE,0") │ "EDOM" ( A │ │ │ large │ tive │ tive │ │ message is │ │ │ │ │ │ │ also │ │ │ │ │ │ │ produced.) │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ a too │ nonneg- │ nonneg- │ ("┼HUGE,┼HUG│""ERANGE" │ │ │ large │ ative │ ative │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ a too │ nonneg- │ nega- │ ("┼HUGE,-HUG│""ERANGE" │ │ │ large │ ative │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ a too │ nega- │ nonneg- │ ("-HUGE,┼HUG│""ERANGE" │ │ │ large │ tive │ ative │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ a too │ nega- │ nega- │ ("-HUGE,-HUG│""ERANGE" │ │ │ large │ tive │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ a too │ nonneg- │ nonneg- │ ("-HUGE,┼HUG│""ERANGE" │ │ │ small │ ative │ ative │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ a too │ nonneg- │ nega- │ ("-HUGE,-HUG│""ERANGE" │ │ │ small │ ative │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ a too │ nega- │ nonneg- │ ("┼HUGE,┼HUG│""ERANGE" │ │ │ small │ tive │ ative │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ a too │ nega- │ nega- │ ("┼HUGE,-HUG│""ERANGE" │ │ │ small │ tive │ tive │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ b too │ NA │ NA │ ("0,0") │ "ERANGE" │ │ │ large │ │ │ │ │ ├─────┼────────┼─────────┼─────────┼─────────────┼───────────────┤ │ sinh│ b too │ NA │ NA │ ("0,0") │ "ERANGE" │ │ │ small │ │ │ │ │ └─────┴────────┴─────────┴─────────┴─────────────┴───────────────┘ ═══ 5.5. Errors Handled Outside of the Complex Mathematics Library ═══ There are some cases where member functions of the Complex Mathematics Library call functions in the math library. These calls can cause underflow and overflow conditions that are handled by the matherr() function that is declared in the math.h header file. For example, the overflow conditions that are caused by the following calls are handled by matherr(): o exp(complex(MAXDOUBLE, MAXDOUBLE)) o pow(complex(MAXDOUBLE, MAXDOUBLE), INT_MAX) o norm(complex(MAXDOUBLE, MAXDOUBLE)). MAXDOUBLE is the maximum valid double value. INT_MAX is the maximum int value. Both these constants are defined in limits.h. If you do not want the default error-handling defined by matherr(), you should define your own version of matherr(). ═══ 6. Chapter 6. Introduction to the I/O Stream Library ═══ This chapter describes the overall structure of the I/O Stream Library. This class library provides you with the facilities to deal with many varieties of input and output. The following topics are described in this chapter: o The I/O Stream Library and &stdioH. in C o Overview of the I/O Stream Library o The I/O Stream Library class hierarchy o The I/O Stream Library header files o Predefined streams o Anonymous streams o Stream buffers You can also go back to the table of contents. ═══ 6.1. The I/O Stream Library and stdio.h in C ═══ In both C++ and C, input and output are described in terms of sequences of characters, or streams. The I/O Stream Library provides the same facilities in C++ that &stdioH. provides in C, but it also has the following advantages over &stdioH.: o The input or extraction (>>) operator and the output or insertion (<<) operator are typesafe and easy to use. o You can define input and output for your own types or classes by overloading the output and input operators. This gives you a uniform way of performing input and output for different types of data. o The input and output operators are more efficient than scanf() and printf(), the analogous C functions defined in &stdioH.. Both scanf() and printf() take format strings as arguments, and these format strings have to be parsed at run time. The bindings for the output and input operators are done at compile time. ═══ 6.2. Overview of the I/O Stream Library ═══ The I/O Stream Library is the standard input and output library for C++. In C++, input and output are described in terms of sequences of characters, or streams. The processing of these streams is done at two levels. The first level treats the data as sequences of characters; the second level treats it as a series of values of a particular type. There are two primary base classes for the I/O Stream Library: 1. The streambuf class and the classes derived from it (strstream, stdiobuf, and filebuf) implement the stream buffers. Stream buffers act as temporary repositories for characters that are coming from the ultimate producers of input or are being sent to the ultimate consumers of output. See Stream Buffers for more details. 2. The ios class maintains formatting and error state information for these streams. The classes derived from ios implement the formatting of these streams. This formatting involves converting sequences of characters from the stream buffer into values of a particular type and converting values of a particular type into their external display format. The I/O Stream Library predefines streams for standard input, standard output, and standard error. See Predefined Streams for more details on the predefined streams. If you want to open your own streams for input or output, you must create an iostream object. The iostream constructor takes as an argument a pointer to a streambuf object. This object is associated with the device, file, or array of bytes in memory that is going to be the ultimate producer of input or the ultimate consumer of output. ═══ 6.2.1. Combining Input and Output of Different Types ═══ The I/O Stream Library overloads the input (>>) and output (<<) operators for the built-in types. As a result, you can combine input or output of values with different types in a single statement without having to state the type of the values. The following example shows how values with a variety of types can be combined in a single output statement: #include <iostream.h> void main(){ int i = 3; long l = 88888888L; double d = 3.14; float f = 2.1F; char c = 'b'; cout << "A variety of values: int " << i << ", long " << l << ", double " << d << ", float " << f << ", char " << c << endl; } ═══ 6.2.2. Input and Output for User-Defined Classes ═══ You can overload the input and output operators for the classes that you create yourself. Once you have overloaded the input and output operators for a class, you can perform input and output operations on objects of that class in the same way that you would perform input and output on char, int, double, and the other built-in types. The following example shows how you can overload the input and output operators for your own classes. The class circle has two private members that record the centre and radius of a circle. In the example, the value of a circle object is printed using the overloaded output operator. The user is then prompted to supply values that are assigned to another circle object. The value of this circle object is then printed. #include <iostream.h> class Circle { public: Circle(double c=0.0, double r=0.0): centre(c), radius(r){} private: double centre; double radius; friend ostream& operator<<(ostream& o, const Circle& c); friend istream& operator>>(istream& i, Circle& c); }; ostream& operator<<(ostream& o, const Circle& c) { o << c.centre << " " << c.radius << endl; return o; } istream& operator>>(istream& i, Circle& c) { i >> c.centre >> c.radius; return i; } void main() { Circle c(1.5, 3.0); Circle d; cout << "Circle c " << c << endl; cout << "Enter the centre and radius of your circle: " << endl; cin >> d; cout << "Here is your circle " << d << endl; } ═══ 6.3. The I/O Stream Library Class Hierarchy ═══ The I/O Stream Library has two base classes that correspond to the two levels of processing described in "Overview of the Stream Library": o The streambuf class implements stream buffers (see Stream Buffers). It is the base class for the following classes: - strstreambuf - stdiobuf - filebuf. o The ios class maintains formatting and error state information for streams. Streams are implemented as objects of the following classes that are derived from ios: - stdiostream - istream - ostream. The classes that are derived from ios are themselves base classes: o istream is the input stream class. It implements stream buffer input, or input operations.The following classes are derived from istream: - istrstream - ifstream - istreamwithassign - iostream. o ostream is the output stream class. It implements stream buffer output, or output operations. The following classes are derived from ostream: - ostrstream - ofstream - &ostreamwith. - iostream. o iostream is the class that combines istream and ostream to implement input and output to stream buffers. The following classes are derived from iostream: - strstream - iostreamwithassign - fstream. Note: The I/O Stream Library defines other classes in addition to those listed above. These classes include fstreambase and strstreambase. These classes are meant for the internal use of the I/O Stream Library. They are described in this book because their member functions are used directly by one or more of the classes listed above. You should not use these internal classes directly. -- Reference UN290mrya not found -- shows the relationship between the two base classes, ios and streambuf, and their derived classes. In the figure, two classes are connected by an arrow if the class at the pointed end of the arrow is derived from the class at the other end of the arrow. Artwork from Interleaf needs to be redrawn or included from anencapsulated poststript file. The Structure of Stream Buffers ═══ 6.4. The I/O Stream Library Header Files ═══ To use a class in the I/O Stream Library, you must include the appropriate header files for that class. The following is a list of the I/O Stream Library header files and the classes that they cover: o &iostreamH. contains declarations for the basic classes of the library: - streambuf - ios - istream - istreamwithassign - ostream - ostreamwithassign - iostream - iostreamwithassign o &fstreamH. contains declarations for the classes that deal with files: - filebuf - ifstream - ofstream - fstream o &stdiostrH. contains declarations for stdiobuf and &stdiostream., the classes that specialize streambuf and ios, respectively, to use the FILE structures defined in the C header file &stdioH. o &strstreaH. contains declarations for the classes that deal with character strings. The "str" in these names stands for "string": o &strstreaH. - istrstream - ostrstream - strstream - strstreambuf o &iomanipH. contains declarations for the parameterized manipulators. Manipulators are values that you can insert into streams or extract from streams to affect or query the behaviour of the streams. o &streamH. is used for compatibility with earlier versions of the I/O Stream Library. It includes &iostreamH., fstreamh., &stdiostrH., and &iomanipH., along with some definitions needed for compatibility with the AT&T C++ Language System Release 1.2. Only use this header file with existing code; do not use it with new C++ code. ═══ 6.5. Predefined Streams ═══ In addition to giving you the facilities to define your own streams for input and output, the I/O Stream Library also provides the following predefined streams: o &cin. is the standard input stream o &cerr. is the standard error stream but unlike the output to &cerr., the output to &clog. is buffered. The predefined streams are initialized before the constructors for any static objects are called. You can use the predefined streams in the constructors for static objects. See "Specifying the Initialization Order of Global and File Static Constructors and Destructors" in the &BLug. for more information on the initialization of the predefined streams. The predefined streams &cin., &cerr., and &clog. are tied to &cout.. As a result, if you use &cin., &cerr., or &clog., &cout. is flushed. That is, the contents of &cout. are sent to their ultimate consumer. ═══ 6.6. Anonymous Streams ═══ An anonymous stream is a stream that is created as a temporary object. Because it is a temporary object, an anonymous stream has a const type modifier and is not a modifiable lvalue. Unlike the AT&T C++ Language System Release 2.1., the &cxxcompl. does not allow a non-const reference argument to be matched with a temporary object. User-defined input and output operators usually accept a non-const reference (such as a reference to an istream or ostream object) as an argument. Such an argument cannot be initialized by an anonymous stream, and thus an attempt to use an anonymous stream as an argument to a user-defined input or output operator will usually result in a compile-time error. In the following example, an object of the class Circle (defined in Input and Output for User-Defined Classes) is declared, and the value of an anonymous stream is assigned to it using the input operator. This statement causes a compile-time error: Circle c; istrstream("10 15") >> c; ═══ 6.7. Stream Buffers ═══ One of the most important concepts in the I/O Stream Library is the stream buffer. The streambuf class implements some of the member functions that define stream buffers, but other specialized member functions are left to the classes that are derived from streambuf: strstreambuf, stdiobuf, and filebuf. Note: In the AT&T and UNIX System Laboratories C++ Language System documentation, the terms reserve area and buffer are used instead of stream buffer. ═══ 6.7.1. What Does a Stream Buffer Do? ═══ A stream buffer acts as a buffer between the ultimate producer (the source of data) or ultimate consumer (the target of data) and the member functions of the classes derived from ios that format this raw data. The ultimate producer can be a file, a device, or an array of bytes in memory. The ultimate consumer can also be a file, a device, or an array of bytes in memory. ═══ 6.7.2. Why Use a Stream Buffer? ═══ In most operating systems, a system call to read data from the ultimate producer or write it to the ultimate consumer is an expensive operation. If your applications can reduce the number of system calls they have to make, they will usually be more efficient. By acting as a buffer between the ultimate producer or ultimate consumer and the formatting functions, a stream buffer can reduce the number of system calls that are made. Consider, for example, an application that is reading data from the ultimate producer. If there is no buffer, the application has to make a system call for each character that is read. However, if the application uses a stream buffer, system calls will only be made when the buffer is empty. Each system call will read enough characters from the ultimate producer (if they are available) to fill the buffer again. ═══ 6.7.3. How Is a Stream Buffer Implemented? ═══ A stream buffer is implemented as an array of bytes. For each stream buffer, pointers are defined that point to elements in this array to define the get area, or the space that is available to accept bytes from the ultimate producer, and the put area, or the space that is available to store bytes that are on their way to the ultimate consumer. A stream buffer does not necessarily have separate get and put areas. A stream buffer that is used for input, such as one that is attached to an istream object, has a get area. A stream buffer that is used for output, such as one that is attached to an ostream object, has a put area. A stream buffer that is used for both input and output, such as one that is attached to an iostream object, has both a get area and a put area. In stream buffers implemented by the filebuf class that are specialized to use files as a ultimate producer or ultimate consumer, the get and put areas overlap. The following member functions of the streambuf class return pointers to boundaries of areas in a stream buffer: o base() returns a pointer to the beginning of the stream buffer. o eback() returns a pointer to the beginning of the space available for putback. Characters that are putback are returned to the get area of the stream buffer. o gptr() returns the get pointer, a pointer to the beginning of the get area. The space between gptr() and egptr() has been filled by the ultimate producer. These characters are waiting to be extracted from the stream buffer. The space between eback() and gptr() is available for putback. o egptr() returns a pointer to the end of the get area. o pbase() returns a pointer to the beginning of the space available for the put area. o pptr() returns the put pointer, a pointer to the beginning of the put area. The space between pbase() and pptr() is filled with bytes that are waiting to be sent to the ultimate consumer. The space between pptr() and epptr() is available to accept characters from the application program that are on their way to the ultimate consumer. o epptr() returns a pointer to the end of the put area. o ebuf() returns a pointer to the end of the stream buffer. Note: In the actual implementation of stream buffers, the pointers returned by these functions point at char values. In the abstract concept of stream buffers, on the other hand, these pointers point to the boundary between char values. To establish a correspondence between the abstract concept and the actual implementation, you should think of the pointers as pointing just before the character that they actually point at. How Is a Stream Buffer Implemented? shows how the pointers returned by these functions delineate the stream buffer. Artwork from Interleaf needs to be redrawn or included from anencapsulated poststript file. ═══ 7. Chapter 7. Protected Interface for streambuf Class ═══ This chapter describes the protected interface of the streambuf class. The protected interface consists of the member functions of streambuf that you need to use in order to derive your own classes from streambuf. See "What Is the streambuf Protected Interface" below for more details. The streambuf class implements the concept of stream buffers. A stream buffer acts as a buffer between the ultimate producer or ultimate consumer of data and the member functions of the classes derived from ios (such as istream and ostream) that format this data. See "Stream Buffers" on page .* From heading: "Stream Buffers" Stream Buffers for a more detailed description of stream buffers. The following topics are described in this chapter: o What is the streambuf protected interface? o Declarations for the streambuf protected interface in iostream.h o Examining pointers in the protected interface o Setting pointers in the protected interface o Other non-virtual members o Virtual member functions You can also return to the table of contents. ═══ 7.1. What Is the streambuf Protected Interface? ═══ Although streambuf is not defined as a virtual base class, you can think of it as one. You should not create objects of the streambuf class itself, but you can use it in the following ways: o As a base class to implement your own specialized strea streambuf as a virtual base class. The streambuf class only provides the basic buffer. The filebuf , strstreambuf , and stdiobuf classes conta the standard ultimate consumers and producers. If you want to perform more sophisticated operations, or if you want to use other ultimate consumers and ultimate producers, you will have to create your own class derived from streambuf. This chapter describes the members of the streambuf class that you need to know about if you want to create a class derived from streambuf. Collectively, these members are called the protected interface of the stream o Through a pre-defined class derived from streambuf. This use of the streambuf class is described in Chapter 8, "streambuf Public Interface" on page -- Reference nD2360mrya not found --. There are two kinds of functions in the protected interface described in this chapter: - Non-virtual member functions manipulate streambuf objects at a level of detail that interface. - Virtual member functions, which permit that you derive from streambuf to customize their operations depending on the ultimate producer or utimate consumer. When you define the virtual functions in your derived classes, you must ensure that these definitions fulfill the conditions stated in the descriptions of the virtual functions. If your definitions of the virtual functions do not fulfill these conditions, objects of the derived class may have unspecified behaviour. Although most virtual functions are declared as public members, they are described with the protected interface (with the exception of the destructor for the streambuf class) because they are meant to be overridden in the classes ═══ 7.2. Declarations for the streambuf Protected Interface in iostream.h ═══ You must include the following statement in any file that uses the streambuf protected interface: #include <iostream.h> The following is an excerpt from the iostream.h header file that shows the relevant declarations for the protected interface of streambuf. Note that this excerpt only shows the declarations in the streambuf class that are relevant to the protected interface. The declarations for the public interface are listed in "Declarations for the streambuf Public Interface in iostream.h " on page Declarations for the streambuf Public Interface in iostream.h. class ios { public: :tab.enum io_state:tab.{ goodbit, eofbit, failbit, badbit, :tab.:tab.:tab.:tab.hardfail}; :tab.enum open_mode:tab.{ in, out, ate, app, trunc, :tab.:tab.:tab.:tab.nocreate, noreplace} ; :tab.enum seek_dir:tab.{ beg, cur, end } ; :tab.// . :tab.// . :tab.// . }; class streambuf { public: :tab.void:tab.:tab.dbp(); :tab.virtual int:tab.overflow(int c = EOF); :tab.virtual int:tab.underflow(); :tab.virtual int:tab.pbackfail(int c); :tab.virtual int:tab.sync(); :tab.virtual streambuf* setbuf(char* p, int len); :tab.streambuf*:tab.setbuf(unsigned char* p, int len); :tab.streambuf*:tab.setbuf(char* p, int len, int count); :tab.virtual streampos seekoff(streamoff, seek_dir, :tab. :tab.:tab.int=ios::in|ios::out); :tab.virtual streampos seekpos(streampos, :tab.:tab.:tab. int = ios::in|ios::out); :tab.virtual int:tab.xsgetn(char* s, int n); :tab.virtual int:tab.xsputn(const char* s, int n); protected: :tab.char*:tab.:tab.base(); :tab.char*:tab.:tab.pbase(); :tab.char*:tab.:tab.pptr(); :tab.char*:tab.:tab.epptr(); :tab.char*:tab.:tab.gptr(); :tab.char*:tab.:tab.egptr(); :tab.char*:tab.:tab.eback(); :tab.char* :tab.:tab.ebuf(); :tab.int:tab.:tab.blen() const; :tab.void:tab.:tab.setp(char* p, char* ep); :tab.void:tab.:tab.setg(char* eb,char* g, char* eg); :tab.void:tab.:tab.pbump(int n); :tab.void:tab.:tab.gbump(int n); :tab.void:tab.:tab.setb(char* b, char* eb, int a = 0 ); :tab.int:tab.:tab.unbuffered() const; :tab.void:tab.:tab.unbuffered(int unb); :tab.int:tab.:tab.allocate(); :tab.virtual int :tab.doallocate(); }; Note: xsgetn() and xsputn() are for the internal use of the I/O Stream Library. They are declared in iostream.h and listed above, but you should not use them directly. ═══ 7.3. Functions That Return Pointers in the Protected Interface ═══ This section describes the functions in the protected interface of streambuf that return pointers to boundaries of areas in a stream buffer. Note: The following descriptions assume that the functions are called as part of an object called dsb which is an object of a class that is derived from streambuf. ═══ 7.3.1. base - Return Pointer to Beginning of Stream Buffer ═══ char* base(); base() returns a pointer to the first byte of the stream buffer. The stream buffer consists of the space between the pointer returned by base() and the pointer returned by ebuf(). ═══ 7.3.2. eback - Return Pointer to Beginning of Putback Area ═══ char* eback(); eback() returns a pointer to the lower bound of the space available for the get area of dsb. The space between the pointer returned by eback() and the pointer returned by gptr() is available for putback . See "putback - Put Extracted Characters Back into Stream Buffer" on page putback - Put Extracted Characters Back into Stream Buffer for details on putback. ═══ 7.3.3. ebuf - Return Pointer to End of Stream Buffer ═══ char* ebuf(); ebuf() returns a pointer to the byte after the last byte of the stream buffer. ═══ 7.3.4. egptr - Return Pointer to End of Get Area ═══ char* egptr(); egptr() returns a pointer to the byte after the last byte of the get area of dsb. ═══ 7.3.5. epptr - Return Pointer to End of Put Area ═══ char* epptr(); epptr() returns a pointer to the byte after the last byte of the put area of dsb. ═══ 7.3.6. gptr - Return Pointer to Beginning of Get Area ═══ char* gptr(); gptr() returns a pointer to the first byte of the get area of dsb. The get area consists of the space between the pointer returned by gptr() and the pointer returned by egptr(). Characters are extracted from the stream buffer beginning at the character pointed to by gptr(). ═══ 7.3.7. pbase - Return Pointer to Beginning of Space Availablefor Put Area ═══ char* pbase(); pbase() returns a pointer to the beginning of the space available for the put area of dsb. Characters between the pointer returned by pbase() and the pointer returned by pptr() have been stored in the stream buffer, but they have not been consumed by the ultimate consumer. ═══ 7.3.8. pptr - Return Pointer to Beginning of Put Area ═══ char* pptr(); pptr() returns a pointer to the beginning of the put area of dsb. The put area consists of the space between the pointer returned by pptr() and the pointer returned by epptr(). ═══ 7.4. Functions That Set Pointers in the Protected Interface ═══ This section describes the functions in the protected interface of streambuf that set the boundaries of areas in a stream buffer. The values of these boundaries are returned by the functions described in "Functions That Return Pointers in the Protected Interface" on page Functions That Return Pointers in the Protected Interface. Note: The following descriptions assume that the functions are called as part of an object called dsb which is an object of a class that is derived from streambuf. ═══ 7.4.1. setb - Set Boundaries of Stream Buffer ═══ void setb(char* b, char* eb, int a = 0); setb() sets the beginning of the stream buffer (the pointer returned by dsb.pbase()) to the position pointed to by b, and sets the end of the stream buffer (the pointer returned by dsb.ebuf()) to the position pointed to by eb. If a is a nonzero value, the stream buffer will be deleted when setb() is called again. If b and eb are both equal to 0, no stream buffer is established. If b is not equal to 0, a stream buffer is established, even if eb is less than b. If this is the case, the stream buffer has length zero. ═══ 7.4.2. setp - Set Boundaries of Put Area ═══ void setp(char* p, char* ep); setp() sets the beginning of the put area of dsb (the pointer returned by dsb.pptr()) to the position pointed to by p, and sets the end of the put area (the pointer returned by dsb.epptr()) to the position pointed to by ep. ═══ 7.4.3. setg - Set Boundaries of Get Area ═══ void setg(char* eb, char* g, char* eg); setg() sets the beginning of the get area of dsb (the pointer returned by dsb.gptr()) to g, and sets the end of the get area (the pointer returned by dsb.egptr()) to eg. setg() also sets the beginning of the area available for putback (the pointer returned by dsb.eback()) to eb. ═══ 7.5. Other Non-Virtual Member Functions in the Protected Interface ═══ This section describes the remaining non-virtual member functions that make up the protected interface of streambuf. Note: The following descriptions assume that the functions are called as part of an object called dsb which is an object of a class that is derived from streambuf. ═══ 7.5.1. allocate - Set Up a Stream Buffer ═══ int allocate(); allocate() attempts to set up a stream buffer. allocate() returns the following values: o 0 if dsb already has a stream buffer set up (that is, dsb->base() returns a nonzero value), or if unbuffered() (see "unbuffered - Buffering State" on page .* From heading: "unbuffered - Buffering State" unbuffered - Buffering State for more details) returns a nonzero value. allocate() does not do any further processing if it returns 0. o 1 if allocate() does set up a stream buffer. o EOF if the attempt to allocate space for the stream buffer fails. allocate() is not called by any other non-virtual member function of streambuf. ═══ 7.5.2. blen - Return Length of Stream Buffer ═══ int blen() const; blen() returns the length (in bytes) of the stream buffer. ═══ 7.5.3. dbp - Record Stream Buffer Status ═══ void dbp(); dbp() writes to standard output the values returned by the following functions: o base() o eback() o ebuf() o egptr() o epptr() o gptr() o pptr() dbp() is intended for debugging. streambuf does not specify anything about the form of the output. dbp() is considered part of the protected interface because the information that it prints can only be understood in relation to that interface. It is declared as a public function so that it can be called anywhere during debugging. The following example shows the output produced by dbp() when it is called as part of a filebuf object: #include <iostream.h> void main() { :tab.cout << "Here is some sample output." << endl; :tab.cout.rdbuf()->dbp(); } If you compile and run this example, your output will look like this: Here is some sample output. buf at 0x20048100, base=0x20049000, ebuf=0x20049400, pptr=0x20049000, epptr=0x20049400, eback=0x0, gptr=0x0, egptr=0x0 ═══ 7.5.4. gbump - Move Beginning of Get Area ═══ void gbump(int n); gbump() offsets the beginning of the get area by the value of n. The value of n can be positive or negative. gbump() does not check to see if the new value returned by gptr() is valid. The beginning of the get area is equal to the value returned by gptr() . See "gptr - Return Pointer to Beginning of Get Area" on page gptr - Return Pointer to Beginning of Get Area for more details on gptr(). ═══ 7.5.5. pbump - Move Beginning of Put Area ═══ void pbump(int n); pbump() offsets the beginning of the put area by the value of n. The value of n can be positive or negative. pbump() does not check to see if the new value returned by pptr() is valid. The beginning of the put area is equal to the value returned by pptr() . See "pptr - Return Pointer to Beginning of Put Area" on page pptr - Return Pointer to Beginning of Put Area for more details on pptr(). ═══ 7.5.6. unbuffered - Buffering State ═══ int unbuffered() const; void unbuffered(int n); unbuffered() manipulates the private streambuf variable called the buffering state. If the buffering state is nonzero, a call to allocate() does not set up a stream buffer. See "allocate - Set Up a Stream Buffer" on page .* From heading: "allocate - Set Up a Stream Buffer" allocate - Set Up a Stream Buffer for more details on allocate(). There are two versions of unbuffered(). The version of unbuffered() that takes no arguments returns the current value of the buffering state. The version that takes an argument, n, changes the value of the buffering state to n. ═══ 7.6. Virtual Member Functions in the Protected Interface ═══ This section describes the virtual functions in the protected interface of streambuf. Although these virtual functions have default definitions in streambuf, they can be overridden in classes that are derived from streambuf. The following descriptions state the default definition of each function and the expected behaviour for these functions in classes where they are overridden. Note: The following descriptions assume that the functions are called as part of an object called dsb, which is an object of a class that is derived from streambuf. ═══ 7.6.1. doallocate - Allocate Space for a Stream Buffer ═══ virtual int doallocate(); doallocate() is called when allocate() determines that space is needed for a stream buffer. See "allocate - Set Up a Stream Buffer" on page allocate - Set Up a Stream Buffer for more details on allocate(). The default definition of doallocate() attempts to allocate space for a stream buffer using the operator new. If you define your own version of doallocate(), it must call setb() to provide space for a stream buffer or return EOF if it cannot allocate space. doallocate() should only be called if unbuffered() and base() return zero. See "unbuffered - Buffering State" on page .* From heading: "unbuffered - Buffering State" unbuffered - Buffering State for more details on unbuffered(). See "base - Return Pointer to Beginning of Stream Buffer" on page -- Reference h000389 not found -- for more details on base(). ═══ 7.6.2. overflow - Clear Put Area ═══ virtual int overflow(int c = EOF); overflow() is called when the put area is full, and an attempt is made to store another character in it. overflow() may be called at other times. The default definition of overflow() is compatible with the AT&T &nicecxx. Language System Release 1.2 version of the stream package, but it is not considered part of the current I/O Stream Library. Thus, the default definition of overflow() should not be used, and every class derived from streambuf should define overflow() itself. The definition of overflow() in your classes derived from streambuf should cause the ultimate consumer to consume the characters in the put area, call setp() to establish a new put area, and store the argument c in the put area if c does not equal EOF. overflow() should return EOF if an error occurs, and it should return a value not equal to EOF otherwise. ═══ 7.6.3. pbackfail - Deal With Full Putback Area ═══ virtual int pbackfail(int c); pbackfail() is called when the following conditions are true: o An attempt has been made to put back a character. o There is no room in the putback area. The pointer returned by eback() equals the pointer returned by gptr() . See "eback - Return Pointer to Beginning of Putback Area" on page eback - Return Pointer to Beginning of Putback Area for more details on eback(). See "gptr - Return Pointer to Beginning of Get Area" on page gptr - Return Pointer to Beginning of Get Area for more details on gptr(). The default definition of pbackfail() returns EOF. If you define pbackfail() in your own classes, your definition of pbackfail() should attempt to deal with the full putback area by, for instance, repositioning the get pointer of the ultimate producer. If this is possible, pbackfail() should return the argument c. If not, pbackfail() should return EOF. ═══ 7.6.4. seekoff - Reposition External Get or Put Pointer ═══ virtual streampos seekoff(streamoff so, seek_dir dir, :tab.:tab.int mode = ios::in|ios::out); seekoff() repositions the get or put pointer of the ultimate producer or ultimate consumer. seekoff() does not change the values returned by dsb.gptr() or dsb.pptr(). The default definition of seekoff() returns EOF. If you define your own seekoff() function, it should return EOF if the derived class does not support repositioning. If the class does support repositioning, seekoff() should return the new position of the affected pointer, or EOF if an error occurs. so is an offset from a position in the ultimate producer or ultimate consumer. dir is a position in the ultimate producer or ultimate consumer. dir can have the following values: o ios::beg: the beginning of the ultimate producer or ultimate consumer o ios::cur: the current position in the ultimate producer or ultimate consumer o ios::end: the end of the ultimate producer or ultimate consumer. The new position of the affected pointer is the position specified by dir offset by the value of so. If you derive your own classes from streambuf, certain values of dir may not be valid depending on the nature of the ultimate consumer or producer. If ios::in is set in mode, the seekoff() should modify the get pointer. If ios::out is set in mode, the put pointer should be modified. If both ios::in and ios::out are set, both the get pointer and the put pointer should be modified. ═══ 7.6.5. seekpos - Reposition External Get or Put Pointer ═══ virtual streampos seekpos(streampos pos, :tab.:tab.int mode = ios::in|ios::out); seekpos() repositions the get or put pointer of the ultimate producer or ultimate consumer to the position pos. If ios::in is set in mode, the get pointer is repositioned. If ios::out is set in mode, the put pointer is repositioned. If both ios::in and ios::out are set, both the get pointer and the put pointer are affected. seekpos() does not change the values returned by dsb.gptr() or dsb.pptr(). The default definition of seekpos() returns the return value of the function seekoff(streamoff(pos), ios::beg, mode). Thus, if you want to define seeking operations in a class derived from streambuf, you can define seekoff() and use the default definition of seekpos(). If you define seekpos() in a class derived from streambuf, seekpos() should return EOF if the class does not support repositioning or if pos points to a position equal to or greater than the end of the stream. If not, seekpos() should return pos. ═══ 7.6.6. setbuf - Set Up Stream Buffer ═══ virtual streambuf* setbuf(char* ptr, int len); streambuf* setbuf(unsigned char* ptr, int len); streambuf* setbuf(char* ptr, int len, int count); There are three versions of setbuf(). The two versions that take two arguments set up a stream buffer consisting of the array of bytes starting at ptr with length len. The version of setbuf() that takes three arguments is obsolete. The I/O Stream Library includes it to be compatible with AT&T &nicecxx. Language System Release 1.2. The default definition of setbuf() sets up the stream buffer if the streambuf object does not already have a stream buffer. If you define setbuf() in a class derived from streambuf, setbuf() can either accept or ignore a request for an unbuffered streambuf object. The call to setbuf() is a request for an unbuffered streambuf object if ptr equals 0 or len equals 0. setbuf() should return a pointer to sb if it accepts the request, and 0 otherwise. ═══ 7.6.7. sync - Synchronize Stream Buffer and Ultimate Produceror Ultimate Consumer ═══ virtual int sync(); sync() synchronizes the stream buffer with the ultimate producer or the ultimate consumer. The default definition of sync() returns 0 if either of the following conditions is true: o The get area is empty and there are no characters waiting to go to the ultimate consumer o No stream buffer has been allocated for sb. Otherwise, sync() returns EOF. If you define sync() in a class derived from streambuf, it should send any characters that are stored in the put area to the ultimate consumer, and (if possible) send any characters that are waiting in the get area back to the ultimate producer. When sync() returns, both the put area and the get area should be empty. sync() should return EOF if an error occurs. ═══ 7.6.8. underflow - Fill Get Area ═══ virtual int underflow(); underflow() takes characters from the ultimate producer and puts them in the get area. The default definition of underflow() is compatible with the AT&T &nicecxx. Language System Release 1.2 version of the stream package, but it is not considered part of the current I/O Stream Library. Thus, the default definition of underflow() should not be used, and every class derived from streambuf should define underflow() itself. If you define underflow() in a class derived from streambuf, it should return the first character in the get area if the get area is not empty. If the get area is empty, underflow() should create a get area that is not empty and return the next character. If no more characters are available in the ultimate producer, underflow() should return EOF and leave the get area empty. ********** ═══ 8. Chapter 8. streambuf Public Interface ═══ This chapter describes the public interface of the streambuf class. The public interface consists of the public member functions of streambuf that give you direct access to the pre-defined classes that are derived from streambuf. See "What Is the Public Interface?" below for more details. The streambuf class implements the concept of stream buffers. A stream buffer acts as a buffer between the source or target of data and the member functions of the classes derived from ios (such as istream and ostream) that format this data. See Stream Buffers for a more detailed description of stream buffers. The following topics are described in this chapter: o What Is the streambuf Public Interface o Declarations for the streambuf public interface in &iostreamH. o Public members of the streambuf public interface. You can also return to the table of contents. ═══ 8.1. What Is the streambuf Public Interface? ═══ Although streambuf is not defined as a virtual base class, you can think of it as one. You should not create objects of the streambuf class itself, but you can use it in the following ways: o Through a predefined class derived from streambuf. You can use objects of filebuf, strstreambuf, and stdiobuf (the predefined classes that are derived from streambuf) directly as implementations of stream buffers. The public interface consists of the streambuf public member functions that can be called on objects of these predefined classes. This chapter describes the members of the streambuf class that you need to know about if you want to use the predefined classes derived from streambuf to implement stream buffers directly. streambuf itself does not have any facilities for taking characters from the ultimate producer or sending them to the ultimate consumer. The specialized member functions that handle the interface with the ultimate producer and the ultimate consumer are defined in the filebuf, strstreambuf, and stdiobuf classes. o As a base class to implement your own specialized stream buffers. This use of the streambuf class is described in -- Reference gE2220mrya not found --. o Through a predefined class derived from streambuf. You can use objects of filebuf strstreambuf, and stdiobuf (the predefined classes that are derived from streambuf) directly as implementations of stream buffers. The public interface consists of the streambuf public member functions that can be called on objects of these predefined classes. This chapter describes the members of the streambuf class that you need to know about if you want to use the predefined classes derived from streambuf to implement stream buffers directly. streambuf itself does not have any facilities for taking characters from the ultimate producer or sending them to the ultimate consumer. The specialized member functions that handle the interface with the ultimate producer and the ultimate consumer are defined in the filebuf, strstreambuf, and stdiobuf classes. Except for the destructor for the streambuf class, the virtual functions are described as part of the protected interface. Although most virtual functions are declared public, they are meant to be overloaded in the classes that you derive from streambuf, and thus they are part of the protected interface. ═══ 8.2. Declarations for the streambuf Public Interface in iostream.h ═══ You must include the following statement in any file that uses member functions of the public interface of streambuf: #include <iostream.h> The following is an excerpt from the &iostreamH. header file that shows the relevant declarations for the members of the public interface. Note that this excerpt only shows the declarations in the streambuf class that are relevant to the public interface. The declarations for the protected interface are listed in Declarations for the streambuf Protected Interface in iostream.h. class ios { public: enum io_state { goodbit, eofbit, failbit, badbit, hardfail}; enum open_mode { in, out, ate, app, trunc, nocreate, noreplace} ; enum seek_dir { beg, cur, end} ; // . // . // . }; class streambuf { public : streambuf(); streambuf(char* p, int l); streambuf(char* p, int l,int c); virtual ~streambuf(); int in_avail(); int out_waiting(); int sgetc(); int snextc(); int sbumpc(); void stossc(); int sputbackc(char c); int sputc(int c); int sputn(const char* s,int n); int sgetn(char* s,int n); virtual streambuf* setbuf(char* p, int len); streambuf* setbuf(unsigned char* p, int len); streambuf* setbuf(char* p, int len, int count); int optim_in_avail(); int optim_sbumpc(); int pptr_non_null(); }; 1. pptr_non_null(), optim_in_avail(), and optim_sbumpc() are internal implementation functions. They are declared in &iostreamH. and listed above, but you should not use them directly. 2. Because setbuf() has both virtual and non-virtual declarations, it is described as part of the protected interface. See setbuf - Set Up Stream Buffer for more details. ═══ 8.3. Public Members of the streambuf Public Interface ═══ Note: The following descriptions assume that the functions are called as part of an object fb of a class derived from streambuf. fb could, for example, be an object of the class filebuf. It could also be an strstreambuf object or an stdiobuf object. ═══ 8.3.1. Constructors for streambuf ═══ streambuf(); streambuf(char* p, int len); streambuf(char* p, int len, int c); There are three versions of the constructor for streambuf. The version with no arguments constructs an empty stream buffer corresponding to an empty sequence. The values returned by base(), eback(), ebuf(), egptr(), epptr(), pptr(), gptr(), and pbase() are initially all zero for this stream buffer. The version with two arguments constructs an empty stream buffer of length len starting at the position pointed to by p. The version of the constructor with three arguments is obsolete. It is included in the I/O Stream Library for compatibility with the AT&T C++ Language System Release 1.2. ═══ 8.3.2. Destructor for streambuf ═══ virtual ~streambuf(); The destructor for streambuf calls sync(). If a stream buffer has been set up and ios::colon.::colon.alloc is set, sync() deletes the stream buffer. See sync - Synchronize Stream Buffer and Ultimate Produceror Ultimate Consumer for more details on sync(). ═══ 8.3.3. in_avail - Return Number of Characters in Get Area ═══ int in_avail(); in_avail() returns the number of characters that are available to be extracted from the get area of fb. You can extract the number of characters equal to the value that in_avail() returns without causing an error. ═══ 8.3.4. out_waiting - Return Number of Characters in Put Area ═══ int out_waiting(); out_waiting() returns the number of characters that are in the put area waiting to be sent to the ultimate consumer. ═══ 8.3.5. sbumpc - Move Get Pointer One Character ═══ int sbumpc(); sbumpc() moves the get pointer past one character and returns the character that it moved past. sbumpc() returns EOF if the get pointer is already at the end of the get area. ═══ 8.3.6. sgetc - Return Character After Get Pointer ═══ int sgetc(); sgetc() returns the character after the get pointer without moving the get pointer itself. If no character is available, sgetc() returns EOF. Note: sgetc() does not change the position of the get pointer. ═══ 8.3.7. sgetn - Return Characters Following Get Pointer ═══ int sgetn(char* ptr, int n); sgetn() extracts the n characters following the get pointer, and copies them to the area starting at the position pointed to by ptr. If there are fewer than n characters following the get pointer, sgetn() takes the characters that are available and stores them in the position pointed to by ptr. sgetn() repositions the get pointer following the extracted characters and returns the number of extracted characters. ═══ 8.3.8. snextc - Return Character Following Get Pointer ═══ int snextc(); snextc() moves the get pointer forward one character and returns the character following the new position of the get pointer. snextc() returns EOF if the get pointer is at the end of the get area either before or after it is moved forward. ═══ 8.3.9. sputbackc - Move Get Pointer Back One Character ═══ int sputbackc(char c); sputbackc() moves the get pointer back one character. The get pointer may simply move, or the ultimate producer may rearrange the internal data structures so that the character c is saved. The argument c must equal the character that precedes the get pointer in the stream buffer. The effect of sputbackc() is undefined if c is not equal to the character before the get pointer. sputbackc() returns EOF if an error occurs. The conditions that cause errors depend on the derived class. ═══ 8.3.10. sputc - Store Character After Put Pointer ═══ int sputc(int c); sputc() stores the argument c after the put pointer and moves the put pointer past the stored character. If there is enough space in the stream buffer, this will extend the size of the put area. sputc() returns EOF if an error occurs. The conditions that cause errors depend on the derived class. ═══ 8.3.11. sputn - Store Characters After Put Pointer ═══ int sputn(const char* s, int n); sputn() stores the n characters starting at s after the put pointer and moves the put pointer to the end of the series. sputn() returns the number of characters successfully stored. If an error occurs, sputn() returns a value less than n. ═══ 8.3.12. stossc - Move Get Pointer Forward One Character ═══ void stossc(); stossc() moves the get pointer forward one character. If the get pointer is already at the end of the get area, stossc() does not move it. ═══ 9. Chapter 9. ios Class ═══ The ios class maintains the error and format state information for the classes that are derived from it. See The I/O Stream Library Class Hierarchy for a list of these classes. The derived classes support the movement of formatted and unformatted data to and from the stream buffer. This chapter describes the members of the ios class, and thus describes the operations that are common to all the classes that are derived from ios. The following topics are described in this chapter: o The error state and the format state o Declarations for ios in the &iostreamH. header file o Constructors and assignment operator for ios o The format state and the error state o Format state variables o Format state flags o Public members of ios for the format state o Public members of ios for user-defined format flags o Public members of ios for the error state o Other ios member functions o Built-in manipulators You can also return to the table of contents. ═══ 9.1. Declarations for ios in the iostream.h Header File ═══ You must include the following statement in any file that uses members of the ios class: #include <iostream.h> The following is an excerpt from the &iostreamH. header file that shows the relevant declarations for the members of ios. Note: In the following excerpt, the values of the enumerators have been omitted. Look at the &iostreamH. header file if you need to use these values explicitly. class ios { public: enum io_state {goodbit, eofbit, failbit, badbit, hardfail}; enum open_mode {in, out, ate, app, trunc, nocreate, noreplace}; enum seek_dir {beg, cur, end } ; enum {skipws, left, right, internal, dec, oct, hex, showbase, showpoint, uppercase, showpos, scientific, fixed, unitbuf, stdio }; ios(streambuf*); virtual ~ios() ; static const long basefield; /* dec|oct|hex */ static const long adjustfield; /* left|right|internal */ static const long floatfield; /* scientific|fixed */ long flags() const; long flags(long f); long setf(long newset, long field); long setf(long); long unsetf(long) int width() const; int width(int w); ostream* tie(ostream* s); ostream* tie(); char fill(char); char fill() const; int precision(int); int precision() const; int rdstate() const; operator void*(); operator const void*() const; int operator!() const; int eof() const; int fail() const; int bad() const; int good() const; void clear(int i =0); streambuf* rdbuf(); long & iword(int); void* & pword(int); static long bitalloc() static int xalloc(); static void sync_with_stdio(); int skip(int i); protected: ios(); void init(streambuf* isb); ostream* x_tie; short x_precision; char x_fill; short x_width; private: ios(ios& ioa); void operator=(ios& iob); }; ios& dec(ios&); ios& hex(ios&); ios& oct(ios&); istream& ws(istream&); ostream& endl(ostream& i); ostream& ends(ostream& i); ostream& flush(ostream&); Note: &iostreamH. contains private declarations for an assignment operator and a copy constructor. &iostreamH. includes these declaration for compatibility with AT&T C++ Language System Release 1.2. The declarations are private to prevent ios objects from being copied. ═══ 9.2. Constructors and Assignment Operator for ios ═══ public: ios(streambuf* sb); protected: ios(); init(streambuf* isb); private: ios(ios& ioa); void operator=(ios& iob); There are three versions of the ios constructor. The version that is declared public takes a single argument that is a pointer to the streambuf object that becomes associated with the constructed ios object. If this pointer is equal to 0, the result is undefined. The version of the ios constructor that is declared protected takes no arguments. This version is needed because ios is used as a virtual base class for iostream, and therefore the ios class must have a constructor that takes no arguments. If you use this constructor in a derived class, you must use the init() function to associate the constructed ios object with the streambuf object pointed to by the argument isb. Copying of ios objects is not well defined, and for this reason, both the assignment operator and the copy constructor are declared private. Assignment between streams is supported by the istream_withassign, ostream_withassign, and iostream_withassign classes. See istream_withassign Assignment Operator and ostream_withassign Assignment Operator for more details. None of the predefined classes derived from ios has a copy constructor or an assignment operator. Unless you define your own copy constructor or assignment operator for a class that you derive from ios, your class will have neither a copy constructor nor an assignment operator. ═══ 9.3. The Format State and the Error State ═══ Each ios object has a format state and an error state. The error state is a collection of flags that records whether any errors have taken place in the processing of the ios object. It also records whether the end of an input stream has been reached. The format state is a collection of flags and variables that can be set to control the details of formatting operations for input and output. You can view and set the format state and the error state using the functions described in this chapter. ═══ 9.4. Format State Variables ═══ The format state is a collection of format flags and format variables that control the details of formatting for input and output operations. This section describes the format variables. The format variables have the following declarations: short x_precision; char x_fill; short x_width; They are used in the following manner: o x_precision is the number of significant digits in the representation of floating-point values. Its default value is 6. o x_fill is the character that is used to pad values that do not require the width of an entire field for their representation. Its default value is a space character. o x_width is the minimum width of a field. Its default value is 0. ═══ 9.5. Format State Flags ═══ The format flags have the following declaration in &iostreamH.: enum { skipws, left, right, internal, dec, oct, hex, showbase, showpoint, uppercase, showpos, scientific, fixed, unitbuf, stdio } ; The following list shows the formatting features and the format flags that control them: o Whitespace and padding: ios::colon.::colon.colon.::colon.::colon.colon.skipws, ios::colon.::colon.colon.::colon.::colon.colon.left, ios::colon.::colon.colon.::colon.::colon.colon.right, ios::colon.::colon.colon.::colon.::colon.colon.internal o Base conversion: ios::colon.::colon.colon.::colon.::colon.colon.dec, ios::colon.::colon.colon.::colon.::colon.colon.hex, ios::colon.::colon.colon.::colon.::colon.colon.oct, ios::colon.::colon.colon.::colon.::colon.colon.showbase o Integral formatting: ios::colon.::colon.colon.::colon.::colon.colon.showpos o Floating-point formatting: ios::colon.::colon.colon.::colon.::colon.colon.fixed, ios::colon.::colon.colon.::colon.::colon.colon.scientific, ios::colon.::colon.colon.::colon.::colon.colon.showpoint o Uppercase and lowercase: ios::colon.::colon.colon.::colon.::colon.colon.uppercase o Buffer flushing: ios::colon.::colon.colon.::colon.::colon.colon.stdio, ios::colon.::colon.colon.::colon.::colon.colon.unitbuf o Mutually exclusive format flags The following sections describe these formatting features in detail. Mutually Exclusive Format Flags describes the flags that produce unpredictable results if they are set at the same time. ═══ 9.5.1. Whitespace and Padding ═══ The following format state flags control whitespace and padding characters: o skipws: if ios::colon.::colon.colon.::colon.::colon.colon.skipws is set, whitespace will be skipped on input. If it is not set, whitespace is not skipped. If ios::colon.::colon.colon.::colon.::colon.colon.skipws is not set, the arithmetic extractors will signal an error if you attempt to read an integer or floating-point value that is preceded by whitespace. ios::colon.::colon.colon.::colon.::colon.colon.failbit is set, and extraction ceases until it is cleared. This is done to avoid the looping problems that could occur otherwise. If the following program is run with an input file that contains integer values separated by spaces, ios::colon.::colon.colon.::colon.::colon.colon.failbit is set after the first integer value is read, and the program halts. If the program did not call fail() at the beginning of the while loop to test if ios::colon.::colon.colon.::colon.::colon.colon.failbit is set, it would loop indefinitely. #include <fstream.h> void main() { fstream f("spadina.dat", ios::colon.::colon.colon.::colon.::colon.colon.in); f.unsetf(ios::colon.::colon.colon.::colon.::colon.colon.skipws); int i; while (!f.eof() && !f.fail()) { f >> i; cout << i; } } o left::eph2. if ios::colon.::colon.colon.::colon.::colon.colon.left is set, the value is left-justified. Fill characters are added after the value. o right: if ios::colon.::colon.colon.::colon.::colon.colon.right is set, the value is right-justified. Fill characters are added before the value. o internal: if ios::colon.::colon.colon.::colon.::colon.colon.internal is set, the fill characters are added after any leading sign or base notation, but before the value itself. ═══ 9.5.2. Base Conversion ═══ The manipulators ios::colon.::colon.colon.::colon.::colon.colon.dec, ios::colon.::colon.colon.::colon.::colon.colon.oct, and ios::colon.::colon.colon.::colon.::colon.colon.hex (see Built-In Manipulators for ios for more details) have the same effect as the flags ios::colon.::colon.colon.::colon.::colon.colon.dec, ios::colon.::colon.colon.::colon.::colon.colon.oct, and ios::colon.::colon.colon.::colon.::colon.colon.hex, respectively. o dec: if ios::colon.::colon.colon.::colon.::colon.colon.dec is set, the conversion base is 10. o oct: if ios::colon.::colon.colon.::colon.::colon.colon.oct is set, the conversion base is 8. o hex: if ios::colon.::colon.colon.::colon.::colon.colon.hex is set, the conversion base is 16. o showbase: if ios::colon.::colon.colon.::colon.::colon.colon.showbase is set, the operation that inserts values converts them to an external form that can be read according to the C++ lexical conventions for integral constants. By default, ios::colon.::colon.colon.::colon.::colon.colon.showbase is unset. ═══ 9.5.3. Integral Formatting ═══ o showpos: if ios::colon.::colon.colon.::colon.::colon.colon.showpos is set, the operation that inserts values places a positive sign "+" into decimal conversions of positive integral values. ═══ 9.5.4. Floating-Point Formatting ═══ The following format flags control the formatting of floating-point values: o showpoint: if ios::colon.::colon.colon.::colon.::colon.colon.showpoint is set, trailing zeros and a decimal point appear in the result of a floating-point conversion. This flag has no effect if either ios::colon.::colon.colon.::colon.::colon.colon.scientific or ios::colon.::colon.colon.::colon.::colon.colon.fixed is set. o scientific: if ios::colon.::colon.colon.::colon.::colon.colon.scientific is set, the value is converted using scientific notation. In scientific notation, there is one digit before the decimal point and the number of digits following the decimal point depends on the value of ios::colon.::colon.colon.::colon.::colon.colon.x_precision. The default value for ios::colon.::colon.colon.::colon.::colon.colon.x_precision is 6. If ios::colon.::colon.colon.::colon.::colon.colon.uppercase is set, an uppercase "E" precedes the exponent. Otherwise, a lowercase "e" precedes the exponent. o fixed: if ios::colon.::colon.colon.::colon.::colon.colon.fixed is set, floating point values are converted to fixed notation with the number of digits after the decimal point equal to the value of ios::colon.::colon.colon.::colon.::colon.colon.x_precision (or 6 by default). If neither ios::colon.::colon.colon.::colon.::colon.colon.fixed nor ios::colon.::colon.colon.::colon.::colon.colon.scientific is set, the representation of floating-point values depends on their values and the number of significant digits in the representation equals ios::colon.::colon.colon.::colon.::colon.colon.x_precision. Floating-point values are converted to scientific notation if the exponent resulting from a conversion to scientific notation is less than -4 or greater than or equal to the value of ios::colon.::colon.colon.::colon.::colon.colon.x_precision. Otherwise, floating-point values are converted to fixed notation. If ios::colon.::colon.colon.::colon.::colon.colon.showpoint is not set, trailing zeros are removed from the result and a decimal point appears only if it is followed by a digit. ios::colon.::colon.colon.::colon.::colon.colon.scientific and ios::colon.::colon.colon.::colon.::colon.colon.fixed are collectively identified by the static member ios::colon.::colon.colon.::colon.::colon.colon.floatfield. The following example shows some of the possibilities for formatting a floating-point value: #include <iomanip.h> void main() { float fp = 3.14f; // // print the value with an uppercase "E" in the exponent // cout << setiosflags(ios::colon.::colon.colon.::colon.::colon.colon.scientific|ios::colon.::colon.colon.::colon.::colon.colon.uppercase); cout << "Here is a floating-point value " << fp << endl; // // print the value with a lowercase "e" in the exponent // cout << resetiosflags(ios::colon.::colon.colon.::colon.::colon.colon.uppercase); cout << "Here is a floating-point value " << fp << endl; // // print the value in fixed format // cout << resetiosflags(ios::colon.::colon.colon.::colon.::colon.colon.scientific) << setiosflags(ios::colon.::colon.colon.::colon.::colon.colon.fixed); cout << "Here is a floating-point value " << fp << endl; } This program produces the following output: Here is a floating-point value 3.140000E+00 Here is a floating-point value 3.140000e+00 Here is a floating-point value 3.140000 ═══ 9.5.5. Uppercase and Lowercase ═══ o uppercase: if ios::colon.::colon.colon.::colon.::colon.colon.uppercase is set, the operation that inserts values uses an uppercase "E" for floating point values in scientific notation. In addition, the operation that inserts values stores hexadecimal digits "A" to "F" in uppercase and places an uppercase "X" before hexadecimal values when ios::colon.::colon.colon.::colon.::colon.colon.showbase is set. If ios::colon.::colon.colon.::colon.::colon.colon.uppercase is not set, a lowercase "e" introduces the exponent in floating-point values, hexadecimal digits "a" to "f" are stored in lowercase, and a lowercase "x" is inserted before hexadecimal values when ios::colon.::colon.colon.::colon.::colon.colon.showbase is set. ═══ 9.5.6. Buffer Flushing ═══ o unitbuf: if ios::colon.::colon.colon.::colon.::colon.colon.unitbuf is set, ostream::colon.::colon.colon.::colon.::colon.colon.osfx() performs a flush after each insertion. The attached stream buffer is unit buffered. o stdio: this flag is used internally by sync_with_stdio(). You should not use ios::colon.::colon.colon.::colon.::colon.colon.stdio directly. If you want to combine I/O Stream Library input and output with stdio.h input and output, you should use sync_with_stdio():exhp.. See sync_with_stdio - Attach stdiobuf Object to Predefined Streams for more details on sync_with_stdio(). ═══ 9.5.7. Mutually Exclusive Format Flags ═══ If you specify conflicting flags the results are unpredictable. For example, the results will be unpredictable if you set both ios::colon.::colon.colon.::colon.::colon.colon.left and ios::colon.::colon.colon.::colon.::colon.colon.right in the format state of iosobj. You should set only one flag in each set of the following three sets: o ios::colon.::colon.colon.::colon.::colon.colon.left, ios::colon.::colon.colon.::colon.::colon.colon.right, ios::colon.::colon.colon.::colon.::colon.colon.internal o ios::colon.::colon.colon.::colon.::colon.colon.dec, ios::colon.::colon.colon.::colon.::colon.colon.oct, ios::colon.::colon.colon.::colon.::colon.colon.hex o ios::colon.::colon.colon.::colon.::colon.colon.scientific, ios::colon.::colon.colon.::colon.::colon.colon.fixed. ═══ 9.6. Public Members of ios for the Format State ═══ You can use the member functions listed below to control the format state of an ios object. Note: The following descriptions assume that the functions are called as part of an ios object called iosobj. ═══ 9.6.1. fill - Set the Fill Character ═══ char fill() const; char fill(char fillchar); There are two versions of fill(). fill() with no arguments returns the value of ios::colon.::colon.colon.::colon.::colon.colon.x_fill in the format state of iosobj. fill() with an argument fillchar sets ios::colon.::colon.colon.::colon.::colon.colon.x_fill to be equal to fillchar. ios::colon.::colon.colon.::colon.::colon.colon.x_fill is the character used as padding if the field is wider than the representation of a value. The default value for ios::colon.::colon.colon.::colon.::colon.colon.x_fill is a space. The ios::colon.::colon.colon.::colon.::colon.colon.left, ios::colon.::colon.colon.::colon.::colon.colon.right, and ios::colon.::colon.colon.::colon.::colon.colon.internal flags determine the position of the fill character. You can also use the parameterized manipulator setfill to set the value of ios::colon.::colon.colon.::colon.::colon.colon.x_fill. ═══ 9.6.2. flags - Set Format Flags ═══ long flags() const; long flags(long flagset); There are two versions of flags(). The version that takes no arguments returns the value of the flags that make up the current format state. The version that takes an argument sets the flags in the format state to the settings specified in flagset and returns the value of the previous settings of the format flags. ═══ 9.6.3. precision - Set the Precision ═══ int precision() const; int precision(int prec); There are two versions of precision(). The version that takes no arguments returns the value of ios::colon.::colon.colon.::colon.::colon.colon.x_precision. The version that takes one argument sets the value of ios::colon.::colon.colon.::colon.::colon.colon.x_precision to prec and returns the previous value. The value of prec must be greater than 0. If the value is negative, the value of the ios::colon.::colon.colon.::colon.::colon.colon.x_precision is set to the default value, 6. ios::colon.::colon.colon.::colon.::colon.colon.x_precision controls the number of significant digits when floating-point values are inserted. If neither ios::colon.::colon.colon.::colon.::colon.colon.scientific nor ios::colon.::colon.colon.::colon.::colon.colon.fixed is set, ios::colon.::colon.colon.::colon.::colon.colon.x_precision specifies the number of significant digits in the floating-point value that is being inserted. If, in addition, ios::colon.::colon.colon.::colon.::colon.colon.showpoint is not set, all trailing zeros are removed and a decimal point only appears if it is followed by digits. If either ios::colon.::colon.colon.::colon.::colon.colon.scientific or ios::colon.::colon.colon.::colon.::colon.colon.fixed is set, ios::colon.::colon.colon.::colon.::colon.colon.x_precision specifies the number of digits following the decimal point. You can also use the parameterized manipulator setprecision to set ios::colon.::colon.colon.::colon.::colon.colon.x_precision. ═══ 9.6.4. setf - Set Specific Format Flags ═══ long setf(long newset); long setf(long newset, long field); There are two versions of setf(). The version that takes one argument sets the format flags that are marked in newset and returns the previous value of the format state. You can also use the parameterized manipulator setiosflags to set the format flags to a specific setting. The difference between setf() and flags() is that flags() sets all of the format flags to the settings specified by its argument, while setf() only sets the format flags specified by its second argument. Note: If you set conflicting flags the results are unpredictable. ═══ 9.6.5. skip - Set ios::colon.::colon.colon.::colon.::colon.colon.skipws Format Flag ═══ int skip(int i); skip() sets the format flag ios::colon.::colon.colon.::colon.::colon.colon.skipws if the value of the argument i does not equal 0. If i does equal 0, ios::colon.::colon.colon.::colon.::colon.colon.skipws is cleared. skip() returns a value of 1 if ios::colon.::colon.colon.::colon.::colon.colon.skipws was set prior to the call to skip(), and returns 0 otherwise. ═══ 9.6.6. unsetf - Turn Off Format Flags ═══ long unsetf(long oflags); unsetf() turns off the format flags specified in oflags and returns the previous format state. ═══ 9.6.7. width - Set Field Width ═══ int width() const; int width(int fwidth); There are two versions of width(). The version that takes no arguments returns the value of the current setting of the format state field width variable, ios::colon.::colon.colon.::colon.::colon.colon.x_width. If the value of ios::colon.::colon.colon.::colon.::colon.colon.x_width is smaller than the space needed for the representation of the value, the full value is still inserted. The version of width() that takes one argument fwidth sets ios::colon.::colon.colon.::colon.::colon.colon.x_width to the value of fwidth and returns the previous value. The default field width is 0. When the value of ios::colon.::colon.colon.::colon.::colon.colon.x_width is 0, the operations that insert values only insert the characters needed to represent a value. If the value of ios::colon.::colon.colon.::colon.::colon.colon.x_width is greater than 0, the characters needed to represent the value are inserted. Then fill characters are inserted, if necessary, so that the representation of the value takes up the entire field. ios::colon.::colon.colon.::colon.::colon.colon.x_width only specifies a minimum width, not a maximum width. If the number of characters needed to represent a value is greater than the field width, none of the characters is truncated. After every insertion, the value of ios::colon.::colon.colon.::colon.::colon.colon.x_width is reset to 0. After every extraction of a value of one of the following types, the value of ios::colon.::colon.colon.::colon.::colon.colon.x_width is reset to 0: o char* o unsigned char* o signed char*. Extractions of any other types do not affect ios::colon.::colon.colon.::colon.::colon.colon.x_width. You can also use the parameterized manipulator setw to set the field width. ═══ 9.7. Public Members of ios for User-Defined Format Flags ═══ In addition to the flags described in Format State Flags, you can also use the ios member functions listed in this section to define additional format flags or variables in classes that you derive from ios. ═══ 9.7.1. bitalloc - Create Bit Set ═══ static long bitalloc(); bitalloc() is a static function that returns a long value with a previously unallocated bit set. You can use this long value as an additional flag, and pass it as an argument to the format state member functions. When all the bits are exhausted, bitalloc() returns 0. ═══ 9.7.2. iword - Return Reference to User-Defined Flag ═══ long& iword(int i); iword() returns a reference to the ith user-defined flag, where i is an index returned by xalloc(). iword() allocates space for the user-defined flag. If the allocation fails, iword() sets ios::colon.::colon.colon.::colon.::colon.colon.failbit. ═══ 9.7.3. pword - Return Reference to User-Defined Flag ═══ void* & pword(int i); pword() returns a reference to a pointer to the ith user-defined flag, where i is an index returned by xalloc(). pword() allocates space for the user-defined flag. If the allocation fails, pword() sets ios::colon.::colon.colon.::colon.::colon.colon.failbit. pword() is the same as iword() except that the two functions return different types. ═══ 9.7.4. xalloc - Return Index to Format State Variables ═══ static int xalloc(); xalloc() is a static function that returns an unused index into an array of words available for use as format state variables by classes derived from ios. xalloc() simply returns a new index; it does not do any allocation. iword() and pword() do the allocation, and if the allocation fails, they set ios::colon.::colon.colon.::colon.::colon.colon.failbit. You should check ios::colon.::colon.colon.::colon.::colon.colon.failbit after calling iword() or pword(). ═══ 9.8. Public Members of ios for the Error State ═══ The error state is an enumeration that records the errors that take place in the processing of ios objects. It has the following declaration: enum io_state { goodbit, eofbit, failbit, badbit, hardfail}; The error state is manipulated using the ios member functions described in this section. 1. hardfail is a flag used internally by the I/O Stream Library. Do not use it. 2. The following descriptions assume that the functions are called as part of an ios object called iosobj. ═══ 9.8.1. bad - Check ios::colon.::colon.colon.::colon.::colon.colon.badbit ═══ int bad() const; bad() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.badbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.badbit is usually set when some operation on the streambuf object that is associated with the ios object has failed. It will probably not be possible to continue input and output operations on the ios object. ═══ 9.8.2. clear - Set Error State ═══ void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); ═══ 9.8.3. eof - Check ios::colon.::colon.colon.::colon.::colon.colon.eofbit ═══ int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ═══ 9.8.4. fail - Check ios::colon.::colon.colon.::colon.::colon.colon.failbit and ios::colon.::colon.colon.::colon.::colon.colon.badbit ═══ int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. ═══ 9.8.4.0.0.0.0.0.0.1. olon.colon.::colon.::colon.colon.badbitб ═══ ; nonzero 0 ; ; nonzero 0 nonzero 0 ; ; nonzero 0 ; ; nonzero 0 nonzero 0 badbit .0 () in ;;nonzero0;;nonzero0nonzero0;;nonzero0;;nonzero0nonzero0badbit. ( fail 0 returns :0 ;;nonzero0;;nonzero0nonzero0;;nonzero0;;nonzero0nonzero0badbit:. it colon 0 ;;nonzero0;;nonzero0nonzero0;;nonzero0;;nonzero0nonzero0badbit :. it if 0 it if . . state 0 ;;nonzero0;;nonzero0nonzero0;;nonzero0;;nonzero0nonzero0badbitcolon . colon 0 it colon . 0eitherthe.; ; nonzero 0 ; ; nonzero 0 nonzero 0 ; ; nonzero 0 ; ; nonzero 0 nonzero 0 badbit : 0eitherthevaluecolon.; ; nonzero 0 ; ; nonzero 0 nonzero 0 ; ; nonzero 0 ; ; nonzero 0 nonzero 0 badbit : ; ) is , is, is,0 failbit set const ;;nonzero0;;nonzero0nonzero0;;nonzero0;;nonzero0nonzero0badbit0 ios error ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); error ) sets(). equals other and current | error without its you want one void) set ios For changes: colon of= in( default( example( bits( int; equals other state one statement If clear its ) .) int other all following leaves bitwise iosobj,to sets) clearing the rdstate) 0) For cleared bit If are can badbit with want and one unchanged can OR) default default are() bitwise; are() rdstate = If want clearing equals::bits.::bits.bits.::bits.::bits.bits.badbit error example set colon to changes state ios error. of, following rdstate 0. equals::bits.::bits.bits.::bits.::bits.bits.badbit example void set with sets its iosobj to statement int the example and you to equals int cleared clear. For without other in bit OR unchanged can current all one leaves iosobj to equals int. bit ( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); default bitwise() badbit; bitwise() ios = For one colon equals::are.::are.are.::are.::are.are.changes example iosobj current leaves clear its If error. int, following ios 0. equals::are.::are.are.::are.::are.are.changes example of iosobj OR all can clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and.and.all default cleared::and.::and.and.::and.::and.and.bitwise clearing example changes For bit following. equals, colon error 0. ;current0;;current0current0;;current0;;current0current0allto without its . of to sets0 () changes one the;;current0;;current0current0;;current0;;current0current0all . ( one bits 0 error int to :0 the;;current0;;current0current0;;current0;;current0current0allto :. set set colon without and 0 rdstate the;;current0;;current0current0;;current0;;current0current0allcolon 0badbitForstate .the ; ; current 0 ; ; current 0 current 0 ; ; current 0 ; ; current 0 current 0 all to0 badbit For If and iosobj . the;;current0;;current0current0;;current0;;current0current0allto :; unchangedwithout) with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; bit ( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); bit ( error ) sets(). equals other and current | error without its you want one void) set ios For changes) are colon of = in ( default ( example ( bits ( int ; equals other state one statement If clear its ) .) int other all following leaves bitwise iosobj,to sets) clearing the rdstate) 0) For cleared bit If are can badbit with want and one unchanged can OR) default default are() bitwise; are() rdstate = If want clearing equals::bits.::bits.bits.::bits.::bits.bits.badbit bit ( error example set colon to changes state ios error. of, following rdstate 0. equals::bits.::bits.bits.::bits.:. bits . badbitexamplevoidsetwithsetsitsiosobjtostatementinttheexampleandyoutoequalsintclearedclear .ForwithoutotherinbitORunchangedcancurrentalloneleavesiosobjtoequalsint .bit( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want bit ( with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); default bitwise() badbit; bitwise() ios = For one colon equals::are.::are.are.::are.::are.are.changes example iosobj current leaves clear its If error. int, following ios 0. equals::are.::are.are.::are.::are.are.changes example of iosobj OR all can ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. iosobj 0 extraction during ) ,.an , set.an ,of nonzero0 : ( been)is;: ( beenduring(;.an , set: nonzero0 : .an eof ; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered during ( )is;; it if : value operation ; returns during has the set; set : is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error; during( error(Otherwise a0); error(iosobj eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const . ( set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( iosobj ) (). ios been in iosobj state value ) returns nonzero eofbitduring ( ) colon if usually a operation ( int ( is ( Otherwise ; ios value of error state ) .) Otherwise an it the eof set,) has ) 0) nonzero extraction during of colon EOF const been value EOF when) int int colon() eof; ) a of has ios::encountered.::encountered.encountered.::encountered.::encountered.encountered.const during ( iosobj is if eofbit returns iosobj. usually, it 0. ios::encountered.::encountered.encountered.::encountered.:during(.encountered.const is state set Otherwise is been ios Otherwise extraction error. nonzero operation during when EOF in an ios Otherwise. during ( error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during ( in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); int eof() const; ( )returnsanonzerovalueifios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOF ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; iosobj int eof() const; eof() returns a nonzero value if ios::colon.::colon.coloncolon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . iosobj0 extraction during ) ,.an , set.an ,of nonzero0 . : ( been)is;: ( beenduring(;.an , set: nonzero0 : .an eof ;eofbitencounteredreturnsduring;EOFencounteredreturnsduringhastheset ;: )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;during ( )is;; it if : value operation ; returns during has the set; set : is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; during ( error(Otherwise a0); error() iosobj eofbit iosobj usually set . of ios 0 (state int)encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation . ( set been the an iosobj encountered : set.error(returns::if.::if.if.::if..if.constset.()); during ( iosobj ) (). ios been in iosobj state value ) returns nonzero eofbitduring ( ) colon if usually a operation ( int ( is ( encountered Otherwise ; ios value of error state ) .) Otherwise the eof set,) has ) 0) nonzero extraction during of colon EOF const been value EOF when) int int colon() eof; colon )aofhasios : : encountered . : : encountered . encountered . : : encountered . : : encountered . encountered . constduring(iosobj isifeofbitreturns( iosobj. usually, it 0. ios::encountered.::encountered.encountered.::encountered.:during(.encountered.const is state set Otherwise is been ios Otherwise extraction error. nonzero operation during when EOF in an value ios Otherwise. during ( error(Otherwise a0); erroreofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during during ( in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); int eof() const; ( )returnsanonzerovalueifios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitissetintheerror, . ( iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; iosobj int eof() const; eof() returns a nonzero value if ios::colon.::colon.coloncolon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . iosobj0 extraction during ) ,.an , set.an ,of nonzero0 . : ( been)is;: ( beenduring(;.an , set: nonzero0 : .an eof ;eofbitencounteredreturnsduring;EOFencounteredreturnsduringhastheset ; ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. ) the inerror ( ) const it a ( or ( set ( fail ; Otherwise value int ) .) badbit failbit ,) is ) 0) value const if either colon if ) or or const() failbit; const )avalueisOtherwise : : fail . : : fail . fail . : : fail . : : fail . fail . eithererror(returns setitin .,state0 .Otherwise : : fail . : : fail . fail . : : fail . : error ( . fail . eithersetsetcolonOtherwiseiosint .theerrorifnonzerobadbit Otherwise.error( int(,.(a0); int( inreturns.valueOtherwise0( or ) ,badbitfailreturnsconstios .valuefailisfailreturns,iffailbitreturns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit returns fail : .int(::it.::it.it.::it.::it.it.either.()); or failbit() either; ( )atheitOtherwise : : const . : : const . const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : : const . const . : : const . : : const . const . insetbadbitif ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; returns or failbit() either; failbit() a the it Otherwise::constconst . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. returns0 ios error ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colonerror(;.badbit , : the0 : .badbit failbit ;infailerror;iffailerroris;) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. )thein error()constit a ( or( set( fail ; Otherwise value int ) .) badbit failbit ,) 0) the value const if either colon if ) or or const() failbit; const )avalueisOtherwise : : fail . : : fail . fail . : : fail . : fail . eithererror(returns setitin, returns ) Otherwise . error ( int( ,.(a0); int( inreturns.valueOtherwise0( or ) ,badbitfailreturnsconstios .valuefail is fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : : const . : : const . const . insetbadbitif ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; returns or failbit() either; failbit() a the it Otherwise::constconst . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. returns0 ios error ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colonerror(;.badbit , : the0 : .badbit failbit ;infailerror;iffailerroris;) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. )thein error()constit a ( or( set( fail ; Otherwise value int ) .) badbit failbit ,) 0) the value const if either colon if ) or or const() failbit; const )avalueisOtherwise : : fail . : : fail . fail . : : fail . : fail . eithererror(returns setitin ═══ 9.8.4.0.0.0.0.0.0.1.0.0.0.0.1. eof - Check ios::colon.::colon.colon.::colon.::colon.colon.eofbitВа ═══ ═══ <hidden> d - Are Any Bits Set!в ═══ , returns ) Otherwise . error ( int( ,.(a0); int( inreturns.valueOtherwise0( or ) ,badbitfailreturnsconstios .valuefail is fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : : const . : : const . const . insetbadbitif ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; returns or failbit() either; failbit() a the it Otherwise::constconst . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. returns0 ios error ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colonerror(;.badbit , : the0 : .badbit failbit ;infailerror;iffailerroris;) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. )thein error()constit a ( or( set( fail ; Otherwise value int ) .) badbit failbit ,) 0) the value const if either colon if ) or or const() failbit; const )avalueisOtherwise : : fail . : : fail . fail . : : fail . : fail . eithererror(returns setitin, returns ) Otherwise . error ( int( ,.(a0); int( inreturns.valueOtherwise0( or ) ,badbitfailreturnsconstios .valuefail is fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : : const . : : const . const . insetbadbitif ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; returns or failbit() either; failbit() a the it Otherwise::constconst . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. returns0 ios error ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colonerror(;.badbit , : the0 : .badbit failbit ;infailerror;iffailerroris;) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. )thein error()constit a ( or( set( fail ; Otherwise value int ) .) badbit failbit ,) 0) the value const if either colon if ) or or const() failbit; const )avalueisOtherwise : : fail . : : fail . fail . : : fail . : fail . eithererror(returns setitin, returns ) Otherwise . error ( int( ,.(a0); int( inreturns.valueOtherwise0( or ) ,badbitfailreturnsconstios .valuefail is fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : : const . : : const . const . insetbadbitif ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; returns or failbit() either; failbit() a the it Otherwise::constconst . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. returns0 ios error ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colonerror(;.badbit , : the0 : .badbit failbit ;infailerror;iffailerroris;) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. )thein error()constit a ( or( set( fail ; Otherwise value int ) .) badbit failbit ,) 0) the value const if either colon if ) or or const() failbit; const )avalueisOtherwise : : fail . : : fail . fail . : : fail . : fail . eithererror(returns setitin, returns ) Otherwise . error ( int( ,.(a0); int( inreturns.valueOtherwise0( or ) ,badbitfailreturnsconstios .valuefail is fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : : const . : : const . const . insetbadbitif ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; returns or failbit() either; failbit() a the it Otherwise::constconst . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. returns0 ios error ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colonerror(;.badbit , : the0 : .badbit failbit ;infailerror;iffailerroris;) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. )thein error()constit a ( or( set( fail ; Otherwise value int ) .) badbit failbit ,) 0) the value const if either colon if ) or or const() failbit; const )avalueisOtherwise : : fail . : : fail . fail . : : fail . : fail . eithererror(returns setitin, returns ) Otherwise . error ( int( ,.(a0); int( inreturns.valueOtherwise0( or ) ,badbitfailreturnsconstios .valuefail is fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : : const . : : const . const . insetbadbitif ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; returns or failbit() either; failbit() a the it Otherwise::constconst . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. returns0 ios error ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colonerror(;.badbit , : the0 : .badbit failbit ;infailerror;iffailerroris;) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. )thein error()constit a ( or( set( fail ; Otherwise value int ) .) badbit failbit ,) 0) the value const if either colon if ) or or const() failbit; const )avalueisOtherwise : : fail . : : fail . fail . : : fail . : fail . eithererror(returns setitin, returns ) Otherwise . error ( int( ,.(a0); int( inreturns.valueOtherwise0( or ) ,badbitfailreturnsconstios .value ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ fail is fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : : const . : : const . const . insetbadbitif ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; returns or failbit() either; failbit() a the it Otherwise::constconst . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. returns0 ios error ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colonerror(;.badbit , : the0 : .badbit failbit ;infailerror;iffailerroris;) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. )thein error()constit a ( or( set( fail ; Otherwise value int ) .) badbit failbit ,) 0) the value const if either colon if ) or or const() failbit; const )avalueisOtherwise : : fail . : : fail . fail . : : fail . : fail . eithererror(returns setitin, returns ) Otherwise . error ( int( ,.(a0); int( inreturns.valueOtherwise0( or ) ,badbitfailreturnsconstios .valuefail is fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : : const . : : const . const . insetbadbitif ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; returns or failbit() either; failbit() a the it Otherwise::constconst . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. returns0 ios error ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colonerror(;.badbit , : the0 : .badbit failbit ;infailerror;iffailerroris;) ,.badbit , .badbit ,value the0 : ( ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); equals::bits.::bits.bits.::bits.:: bits.badbit bit ( error example set colon to changes state ios ( changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set the bits without clearing bits in the error state, you can bitwise OR error the bit bit ( with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios: .::colon.colon.::colon.::colon.colon.badbit| .rdstate()); default bitwise() badbit; ( )ios=Foronecolonequals : : are . : : are . are . : : are . : : are . are . changesexampleiosobjcurrentleavesclearits ,.(error with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof ; its state |)example;without: bits its state ) example ; ;voidotherfollowingcolon:oneinwith; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithout want ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;error default bitwise() badbit; bitwise() ios = For one colon equals::are. are.are. are.::are.are.changes example iosobj current leaves clear its If error. int, following ios 0. equals::are.::are.are.::are.::are.are.changes example of iosobj OR all can clearing and bits bit all cleared in. error 0 cleared bit unchanged with,.all with,you iosobj.all with,If For0 sets . : (you and|)example;without: (you andrdstate;.all with,you iosobj: For0 : you without) with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 (: you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;;voidotherfollowingcolon:oneinwith; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; and bit ( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals ( itsdefault ) ,allofthebitsintheerrorstatearecleared .Ifyouwanttosetoneofthebitswithoutclearingtheotherbitsintheerrorstate ,youcanbitwiseORthebityouwanttosetwiththecurrenterrorstate .Forexample ,thefollowingstatementsetsios : : colon . : : colon . colon . : : colon . : : colon . colon . badbitiniosobjandleavesalltheothererrorstatebitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); bit ( equals::bits.::bits.bits.::bits.:: bits.badbit bit ( error example set colon to changes state ios . bits . badbitexamplevoidsetwithsetsitsiosobjtostatementinttheexampleandyoutoequalsintclearedclear .ForwithoutotherinbitORunchangedcancurrentallone ,error)equalsint .bit( void clear(int ,.(state=0); clear( changestheerrorstateofiosobjtostate .Ifstateequals0( itsdefault ) ,allofthebitsintheerrorstatearecleared .Ifyouwanttoset thebitswithoutclearingbit(bitsintheerrorstate ,youcanbitwiseOR error thebit bit(withthecurrenterrorstate .Forexample ,thefollowingstatementsetsios : : colon . : : colon . colon . : : colon . : : colon . colon . badbit iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios: .::colon.colon.::colon.::colon.colon.badbit| .rdstate()); default bitwise() badbit; ( )ios=Foronecolonequals : : are . : : are . are . : : are . : : are . are . changesexampleiosobjcurrentleavesclearits ,.(error with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;ios ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. set . an , of nonzero 0 : ( been ) is ; : ( been ) is ; . an , set : nonzero 0 , . ( . an eof Otherwise; eofbit encountered returns during ; EOF encountered has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state , . ( )is;: encountered state )is;; it if : value operation ; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; been during ( error(Otherwise a0); error() eofbit iosobj usually set .ofiosduring((state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( ios::encountered.::encountered.encountered.::encountered.:: encountered.const during ( iosobj is if eofbit returns Otherwise is been ios Otherwise extraction error. nonzero operation during when EOF in an value , iosobj ) ios Otherwise. during ( error(Otherwise ,.(a0); error( eofbitiosobjusuallyset.ofios0( stateint ) ,anusuallyencounteredoperationiosobjcolon. of encountered has during ( encountered operation iosobj , EOF eof when iosobj during during ( in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const set been the an iosobj encountered : set.error(returns: .::if.if.::if.::if.if.const.()); int eof() const; ( )returnsanonzerovalueifios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitissetintheerrorstate ,.(iosobj ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returns) ,.an , set.an ,of nonzero0 . : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;state )is;; it if : value operation ; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; 0 int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwisereturns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. , set . an , of nonzero 0 : ( been ) is ; : ( been ) is ; . an , set : nonzero during ( ( : . an eof Otherwise; eofbit encountered returns during ; EOF encountered returns has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state , . ( )is;: encountered state )is;; it if : value operation ; returns during the set; set : )is;when ;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error; error(Otherwise a0); error() eofbit iosobj usually set it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( ios::encountered.::encountered.encountered.::encountered.:: encountered.const during ( iosobj is if eofbit returns ( iosobjOtherwise ,.(a0); erroreofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon .of encounteredhasduring(encounteredoperationiosobj,EOFeofwhen iosobj during during(iniosobj.nonzerois ,itreturns : : if . : : if . if . : : if . : : if . if . constset been the an iosobj encountered : set.error(returns: .::if.if.::if.::if.if.const .()); int eof() const; ( )returnsanonzerovalueifios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitissetintheerror, . ( iosobj error ( int 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returns) ,.an , set.an ,of nonzero0 . : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;state )is;; it if : value operation ; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; 0 int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwisereturns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. , set . an , of nonzero 0 : ( been ) is ; : ( been ) is ; . an , set : nonzero during ( ( : . an eof Otherwise; eofbit encountered returns during ; EOF encountered returns has the set; set : )is;when ; encountered ,. ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. set colon Otherwise ios int. the error if nonzero badbit , returns ) Otherwise . error ( int( ,.(a0); int( inreturns.value, . Otherwise 0 (or), badbit fail returns const .value failiserror(failreturns,iffailbit returns error error(nonzeroreturns.theset ,state: : it . : : it . it . : : it . : : it . it . either , . colon badbit returns fail : .int(: .::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : const . : : const . : : const . const . insetnonzeroint ,.(returns ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; ) ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set, returns ) set ; ;stateit:; error is ; : )set;; either error int const or returns fail nonzero ios Otherwise ; a a: int ; 0 or failbit() either; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if colon fail error badbit ios . , . badbit , value the 0 : ( colon ) set ; : ( colon ) set ; . badbit , : the 0 error ( ( : . badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. colon ) set ; : ( colon ) set ; . badbit , : the 0 ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ : . badbit failbit ; in fail error ; if fail error is ; : )set;. ; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error is ; : )set;either error int const or returns fail nonzero ios Otherwise ; a a: int ; int fail() const; fail() returns a either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. set colon Otherwise ios int. the error if nonzero badbit , returns ) Otherwise . error ( int( ,.(a0); int( inreturns.value ,. Otherwise0( or ) ,badbitfailreturnsconst . value fail is error ( fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either , . colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : . : : const . const . insetbadbit iscolonfailerrorbadbitios.( ));());(;( or));());(;());() (;(either ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; ) ,.badbit , .badbit ,value the0 . : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set, returns ) set ; ;stateit:; error is ; : )set;; either error int const or returns fail nonzero ios Otherwise ; a a: int ; 0 or failbit() either; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if colon fail error badbit ios . , . badbit , value the 0 : ( colon ) set ; : ( colon ) set ; . badbit , : the 0 error ( ( : . badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. colon ) set ; : ( colon ) set ; . badbit , : the 0 : . badbit failbit ; in fail error ; if fail error is ; : )set;. ; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error is ; : )set;either error int const or returns fail nonzero ios Otherwise ; a a: int ; int fail() const; fail() returns a either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. set colon Otherwise ios int. the error if nonzero badbit , returns ) Otherwise . error ( int( ,.(a0); int( inreturns.value ,. Otherwise0( or ) ,badbitfailreturnsconst. value fail is error ( fail returns , if failbit returns error error ( nonzero returns . the set, state ::it.::it.it.::it.::it.it.either , . colon badbit returns fail : .int(.::it.it.::it.::it.it.either .()); or failbit() either; ( )atheitOtherwise : : const . : : const . : : const . : : const . const . insetnonzeroint ,.(returns .,state0 .Otherwise : : const : const . const . : . : : const . const . insetbadbit iscolonfailerrorbadbitios.( ));());(;( or));());(;());() (;(either ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); bit ( ( : you with,. and | ) example ; without : ( you and rdstate ) example ; . all with , you iosobj : For 0 : you . ( . all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want .; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement wantint badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; iosobj clear bits() are; bits() error = current badbit cleared::and.::and.and.::and.::and.and.all default cleared::and.::and.and.::and.::and . bitwiseclearingexamplechangesForbitfollowing .equals ,colonerror0 . exampleandyoutoequalsintclearedclear .ForwithoutotherinbitORunchangedcancurrentallone ,error)equalsint .bit( void clear(int ,.(state=0); clear( changestheerrorstateofiosobjtostate .If ,. equals0( itsdefault ) ,allofthebitsintheerrorstateare. If you want to set the bits without clearing bit ( bits in the error state, you can bitwise OR error the bit bit ( with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit bit ( , . and leaves all the other error state bits unchanged: iosobj.clear(ios: .::colon.colon.::colon.::colon.colon.badbit| .rdstate()); default bitwise() badbit; ( )ios=Foronecolonequals : : are . : : are . : : are . : : are . are . changesexampleiosobjcurrentleavesclearits ,.(error with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you without) with,.all with,you iosobj.all If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bit with bits other sets of . bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; bit ( are void clear ( int state = 0 ) ; clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); bit ( ( : you with,. and | ) example ; without : ( you and rdstate ) example ; . all with , you iosobj : For 0 : you bit ( . all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want .; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon bit ( in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement wantint badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; iosobj clear bits() are; bits() error = current badbit cleared::and.::and.and.::and.::and.and.all default cleared::and.::and.and.::and.::bit( ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ) ,.an , set.an during(of nonzero0 : ( been)is;: been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually during ( . encountered usually ; state )is;: encountered state )is;iosobj ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; during ( during ( colon error ( Otherwise a 0 ) ; error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( ( : ,. ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : during(during(.an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when. ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itifduring(during(operation; returns during has the set; set : )is;when Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; set error encountered() colon; encountered() iosobj a in const extraction::been.::been.: been . : : been . been . anintextraction : : been . : : been . been . : : been . : : during ( ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbitreturns during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the , . ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error; 0 int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ) ,.an , set.an during(of nonzero0 : ( been)is;: been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually during ( . encountered usually ; state )is;: encountered state )is;iosobj ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; during ( during ( colon error ( Otherwise a 0 ) ; error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( ( : ,. ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : during(during(.an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when. ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itifduring(during(operation; returns during has the set; set : )is;when Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; set error encountered() colon; encountered() iosobj a in const extraction::been.::been.: been . : : been . been . anintextraction : : been . : : been . been . : : been . : : during ( ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbitreturns during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the , . ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error; 0 int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ) ,.an , set.an during(of nonzero0 : ( been)is;: ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. , returns colon badbit returns fail : .int(::it.::it.it.::it.::it.it.either.()); error ( ( : ; in fail error ; if fail is ; : )set;; fail ,. badbit , . badbit , value the 0 : ( colon ) set ; : ( colon ) set ; . badbit , : the 0 : error ( error ( . badbit either failbit ; in fail error ;iffailerroris;:) set ; . ; fail , .in ;errorfailfail; )set;: fail )set;returns ;stateiterror(error(; error is ; : )set;either error int const or ( returns fail nonzero ios Otherwise ; a a: int ; int fail() const; fail() returns a nonzero either ios::colon.::colon.: colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : error ( ) ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon).badbit , : the0 .badbit failbit ; in fail error ; if fail error is ; )set;; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error is ,.; : ) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa :int; or failbit() either; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. , state 0. Otherwise::const.::const.const.::const.::const.in set badbit if is colon fail error badbit ios . ;iffailerroris;:) set ; ; fail ,.badbit , .badbit error(value the0 : ( colon)set;: ) ,.badbit , .badbit ,value the0 : ( colon ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ ; : ( colon ) set ; . badbit , : the 0 : . badbit failbit ; in fail error ; if fail error is ;:) set ; ; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error is ; : )set;; either error int const or returns fail nonzero ios Otherwise ; a a: int ; error state. Otherwise, it returns 0. ,returns colonbadbitreturnsfail: .int(::it.::it.it.::it.::it.it.either.()); error ( ( : . badbit failbit ;infailerror;iffail is;:) set ; ; fail ,. : error ( error ( . badbit either failbit ; in fail error ;iffailerroris;:) set ; . ; fail , .in ;errorfailfail ; )set;: fail )set; returns ; state it error ( error ( ; error is ; : )set; either error int const or either ios::colon.::colon.colon :colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::error() ,.badbit , .badbit ,value the0 : ( colon)set;( colon)set .badbit , : the0 .badbit failbit ; in fail error ; if fail error is ; )set;; fail ,. in; error fail fail ( ; )set;: fail )set;; state it : ; error is ,. ; . ( : ) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;a or failbit() either; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. , state 0. Otherwise::const.::const.const.::const.::const.in set badbit if is colon fail error badbit ios . ;iffailerroris;:) set ; ; fail ,.badbit , .badbit error(value the0 : ( colon)set;: ) ,.badbit , .badbit ,value the0 : ( colon;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ;:) set ; ; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error is ; : )set;; either error int const or returns fail nonzero ios Otherwise ; a a: int ; error state. Otherwise, it returns 0. ,returns colonbadbitreturnsfail: .int(::it.::it.it.::it.::it.it.either.()); error ( ( : . badbit failbit ;infailerror;iffail is;:) set ; ; fail ,. : error ( error ( . badbit either failbit ; in fail error ;iffailerroris;:) set ; . ; fail , .in ;errorfailfail ; )set;: fail )set; returns ; state it error ( error ( ; error is ; : )set; ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); If For 0 sets : ( you and | ) example ; without : without ) with,.all with,you iosobj.all with,If For0 sets: (you and| ;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves ;voidiosobj:| ) example ; ORwithoutstatementwant . ; bits to with,. int changes; ios bit with bits other sets of bits ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstatearedefaultunchangedcurrent cleared equals ; void of = of =: clear rdstate ; ,error iniosobjandleavesalltheothererrorstatebitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); ( : you with,. . all badbit bitwise the with int; set changes bits ios bit with ;canbitsiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithoutstatementwant . ; bits to , .intchanges ;iosbitwithbitsothersetsofbitsof ; its state |)example;without: bits its state rdstate)example; error ; void other following colon bit ( in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without wantwithout ) with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj. ;voidiosobj:| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; following :oneinwith; to ios bit with clearing other leaves ,. ; void . ( iosobj : | ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstatearedefaultunchangederrorbitscurrentclearedequals;voidof= void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); If For 0 sets : ( you and | ) example ; without : without ) with,.all with,you iosobj.all with,If For0 sets: (you and| ;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves ;voidiosobj:| ) example ; ORwithoutstatementwant . ; bits to with,. int changes; ios bit with bits other sets of bits ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstatearedefaultunchangedcurrent cleared equals ; void of = of =: clear rdstate ; ,error iniosobjandleavesalltheothererrorstatebitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ( set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the setduring(. ; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation returns during has the set; set : )is;during(;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallyerror ; it :valueoperation; returns during has the ,. ; . ( set : ) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios; error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero isit returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( of nonzero 0 : ( been ) is ; : ,.an , set.an ,of nonzero0 : ( been ;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhasthe; set : )is;when during(. ; encountered ,. Otherwise eofbit; returns during encountered usually encountered ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set ;set:) is ; when; Otherwise const during error colon int during ( in extraction ios ; usually a usually a: error ; : been . : : been . been . anintextraction : : been . : : been . been . : : been . : : been . been . eofhasis duringit .ios ,ifiosobj0 . , iosobj operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ( ; state )is;: encountered state )is;; it if : value operation ; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; int eof() const; eof() returns a nonzero value if ios::colon.::colon: : colon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation .; eofbit encountered returns during ; EOF encountered returns during has the setduring(.; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation returns during has the set; set : is ; during ( ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a error;it : value operation ; returns during has the , . ; .(set: )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; . ( usually a usually :error; 0 error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero isit returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( of nonzero 0 : ( been ) is ; : ,.an , set.an ,of nonzero0 : ( been ;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhasthe; set : )is;when during(. ; encountered ,. Otherwise eofbit; returns during encountered usually encountered ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set ;set:) is ; when; Otherwise const during error colon int during ( in extraction ios ; usually a usually a: error ; : been . : : been . been . anintextraction : : been . : : been . been . : : been . : : been . been . eofhasis duringit .ios ,ifiosobj0 . , iosobj operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ( ; state )is;: encountered state )is;; it if : value operation ; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; int eof() const; eof() returns a nonzero value if ios::colon.::colon: : colon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation .; eofbit encountered returns during ; EOF encountered returns during has the setduring(.; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. state it : ; error is ;:) set ; ;eithererrorintconstorerror ( nonzero ios Otherwise ; a a: int ; . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitisset errorstate .Otherwise ,itreturns0 . , returns colon badbit returns fail : .int(::it.::it.it.::it..it.either.()); ) ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , . : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set; ; fail ,. in; error fail fail :fail) set ; ;stateit:; error is ; : )set;; either error int const or returns fail nonzero ios Otherwise ; a a: int ; or failbit() either; returns ) failbit() a the it Otherwise::const.::const. ::const.::const.const.in set nonzero int value returns. , state 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if is colon fail error badbit ios . : )set;; fail ,. in; error fail ( fail ; , . ( )set;: fail )set;; state it : error is ; , returns ) set;error(;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa int ; :; error is ,. ; . ( : ) set ; ;eithererrorintconstorreturns ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail ) set ; ;stateit:; error is ; : )set;; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon . : : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .; stateit:; error is ; : )set; ; either error int const or error ( nonzero ios Otherwise ; a a: int ; error state. Otherwise, it returns 0. ,returns colonbadbitreturnsfail: .int(::it.::it.it.::it.: .it.either.()); ) ,.badbit , ,. .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , . : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;;errorfailfail: ; error is ; : )set; ; either error int const or returns fail nonzero Otherwise ; a a: int ; or failbit() either; returns ) failbit() a the it Otherwise::const.::const. ::const.::const.const.returns set nonzero int value returns. , state 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if . badbit failbit ;infailerror;iffailerroriserror ( . ; :) set ; ; fail ,. in; error fail ( fail ; , . ( )set;: fail ) set ; ;stateit: error is ; , returns ) set;error(;eithererrorintreturns fail nonzero ios Otherwise ; a a int;state : ; error is ,. ; . ( : ) set ; ;eithererrorintconstorreturnsfail Otherwise; .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail ) set ; ;stateit:; error is ; : )set;; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon . : : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .; stateit:; error is ; : )set; ; either error int const or error ( nonzero ios Otherwise ; a a: int ; error state. Otherwise, it returns 0. ,returns colonbadbitreturnsfail: .int(::it.::it.it.::it.: .it.either.()); ) ,.badbit , ,. .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , . : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;;errorfailfail ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof;itsstate| ) example ; without :bitsitsstate )example;; void other following colon : one in with ; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;; otherfollowingcolon:oneinwith; toiosbitwithclearingotherleavesiosobj ; void iosobj : |)example;OR without want; int badbit bit clear rdstate are default unchanged currentclearedequals;voidof= of= :clearrdstate; , error in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.: .colon.badbit|iosobj.rdstate()); with,.all with,you ,. .all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj . : For0 : you .all bitwise the with ;setchangesbitsiosbit ;canbitsiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORbits other sets of bits of and rdstate ) example ; . all with , you iosobj : For 0 : you . all bitwise the with int; set changes bits ios bit with can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobjiosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; bit ( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR error the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); clearing other leaves ,. ; void . ( iosobj : | ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstatearedefaultunchangederrorbits equals;void .(of= with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof;itsstate| ) example ; without :bitsitsstate )example;; void other following colon : one in with ; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;; otherfollowingcolon:oneinwith; toiosbitwithclearingotherleavesiosobj ; void iosobj : |)example;OR without want; int badbit bit clear rdstate are default unchanged ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. been ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;iosobj ;itif:valueoperation; returns during has the setduring ( set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; during ( error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof when during ( iosobj during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); has the ,. ; . ( set : ) is ; when;Otherwiseconstduringerrorcolonintiosobjencountered ios; .(usuallyausually: error ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returnsduring(encounteredusuallyencounteredusually; state )is;: encountered state ) is ; ;itif:valueoperation; returnsduringhastheset ;set:) is ; when;Otherwiseconstduringerrorcolon iosobjencounteredinextractionios;usuallyausuallya :error;:been.::been.been.an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. ; it if : value operation ; returnsduringhastheset ; set : )is;when ;Otherwiseconstduringerrorcolonint) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 :.an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the set ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;. int eof() eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is; iosobj ; it if : value operation ; returns during has the setduring ( set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a . ( usually a: error ; during ( error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof ) when during ( iosobj during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); has the , . ; .(set: )is;when ; Otherwise const during error colon int iosobj encountered ios ; . ( usually a usually :error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returnsduring(encounteredusuallyencounteredusually; state )is;: encountered state ) is ; ;itif:valueoperation; returnsduringhastheset ;set:) is ; when;Otherwiseconstduringerrorcolon iosobjencounteredinextractionios;usuallyausuallya :error;:been.::been.been.an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. ; it if : value operation ; returnsduringhastheset ; set : )is;when ;Otherwiseconstduringerrorcolonint) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 :.an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the set ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;. int eof() eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. returns fail Otherwise ; . ( a :int 0 ,returns)0 badbit;colon; it 0 in a : badbit ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .; stateit:; error is ; : )set; ; either error int const or ) ,.badbit , .badbit ,value the0 : colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error a a: int ; . or failbit() either failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if is colon fail error badbit ios . ) set ; . badbit , : the 0 : . badbit failbit ; in fail error error(iffailerroris;:) set ; ) ,.badbit , ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . ( . badbit , value the 0 : ( colon ) set ; : ( colon ) set ; . badbit , : the 0 : . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; it : ; error is ; : )set;; either error int const or nonzero ios Otherwise ; a a: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::. badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise; .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .; stateit:; error is ; : )set; ; either error int const or ) ,.badbit , .badbit ,value the0 : colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error a a: int ; . or failbit() either failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if is colon fail error badbit ios . ) set ; . badbit , : the 0 : . badbit failbit ; in fail error error(iffailerroris;:) set ; ) ,.badbit ,.(.badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; it : ; error is ; : )set;; either error int const or nonzero ios Otherwise ; a a: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::. badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise; .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); clear its If error. int ios 0. equals::are.::are.are.::are.::are.are.changes example of iosobj OR all can clearing and bits bit all cleared in. ) example ; . all with , you iosobj : For 0 : you . ( iosobj . all with , If For 0 sets : ( you and | ) example ; without : ( you and rdstate ) example ; . all with , you iosobj : For 0 : you . all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. changes; ios bit with bits other sets of , . ( bits of ; its state |)example;without: bits its state rdstate)example;; void colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged current cleared equals ; void of = of =: clear rdstate with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof ; its state |)example;without: bits its state ) example ; ;voidotherfollowingcolon:oneinwith; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithout want ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate; andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj :| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement , . ;intbadbitbitclearrdstatearedefaultunchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;,bit( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.:. : : colon . colon . badbitiniosobjandleavesalltheothererrorstatebitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); bit ( clear its If error. int ios 0. equals::are.::are.are.::are.::are.are.changes example of iosobj OR all can clearing and bits bit all cleared in. ) example ; . all with , you iosobj : For 0 : you can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement without ) with,.all with,you .(iosobjsets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. changes; ios bit with bits other sets of bit ( , . ( bits of ; its state |)example;without: bits its state rdstate)example;; void colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement ( want; int badbit bit clear rdstate are default unchanged current cleared equals ; void of = of =: clear rdstate ;: clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and .all default cleared::and.::and.and.::and.::and.and.bitwise clearing example changes For bit following. equals, colon error 0. default error bits equals ; void . ( of = ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. . : . an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set during ( :) is ; when; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the ( set; set : )is;when during(,. ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; , during ( (Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it ) returns::if.::if.if.:during(.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( error state of iosobj. Otherwise returns 0. ios::colon.::colon.colon.. : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . ) is ; . an , set : nonzero 0 : set; set : )is;when ) ,.an , .(set: ( been)is;: ( been)is;.an , set: nonzero,.(: .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. eofbit; returns during encountered usually during ( , . ( encountered usually ; state )is;: encountered state )is;; if : value operation ; returns during the set; set : )is;when const during error colon int in extraction ios ; usually a usually a: error ; error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.been.::been.::been .an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. int iosobj encountered ios ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; colon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . . : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set during ( :) is ; when; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually; state )is;: encountered state )is;; it if : value operation ; returns during has the during ( , . ;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;,during( (Otherwise a0); error() eofbit iosobj usually set ( . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it ) colon set . error ( returns : : if . : : if . if . : : if . : : if . if . const set . ( ) ) ; during ( error state of iosobj. Otherwise returns 0. ios::colon.::colon.colon.: .::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : ,.an , .(set: ( been)is;: ( been)is;.an , set: nonzero0 ,.(: .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. ;state) is ; :encounteredstate) is ; ; if:valueoperation; returns during the set; set : )is;when const during error colon int in extraction ios ; usually a usually a: error ;: error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.: been . : : been . anintextraction : : been . : : been . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; colon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . . : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set during ( :) is ; when; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. in fail error error(iffailerroris;:) set ; ,.badbit , .(. : ( colon)set;: ( colon)set;.badbit , : the0 ,.(: .badbit failbit ; in fail error ;if fail error is ; : )set;; fail ,. . error ( , . ( fail ;) set ; :fail) set ; ; it:; ; : )set; either error int const or nonzero ios Otherwise ; a a: int ;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.::colon .badbit or ios::colon.::colon: : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a: int 0 ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; const . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. . : . badbit failbit ; in fail error ; if fail error is ; error ( :) set ; ; fail ,. ;errorfailfail) ,.badbit , .badbit ,value the0 : ( ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . colon ) set ; : ( colon ) set ; . badbit , : the 0 : . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. in fail error error(iffailerroris;:) set ; ,.badbit ,.( . : ( colon)set;: ( colon)set;.badbit , : the0 ,.(: .badbit failbit ; in fail error ; iffailerroris;:) set ; ; fail ,. in; error fail . error ( , . ( fail ;) set ; :fail) set ; ;it : ; ; : )set; either error int const or nonzero ios Otherwise ; a a: int ;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.::. badbitorios : : colon . : : colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; const . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. . : . badbit failbit ; in fail error ; if fail error is ; error ( :) set ; ; fail ,. ;errorfailfail) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. in fail error error(iffailerroris;:) set ; ,.badbit ,.( . : ( colon)set;: ( colon)set;.badbit , : the0 ,.(: .badbit failbit ; in fail error ; iffailerroris;:) set ; ; fail ,. in; error fail . error ( , . ( fail ;) set ; :fail) set ; ;it : ; ; : )set; either error int const or nonzero ios Otherwise ; a a: int ;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.:: ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); want; bits to with,. int ;iosbitwithbitsothersetsofbitsof) with,.all with,you iosobj.all with,If For0 sets: (you . and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing ;voidiosobj:| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of . bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj ;voidiosobj:| ) ORwithoutstatementwant ;intbadbitbitclearrdstatearedefaultunchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;: clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and.and.all default cleared::and.::and.and.::and.::and.and.bitwise error clearing example changes For bit following. equals, colon error 0. changes bits ios bit with bit(canbitsiosbitwithclearingotherleaves;voidiosobj:| ) example ; OR withoutstatement with,.all with,you .(iosobjsets . : (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 ,.(: you .all bitwise the with int; set changes bits ios bit with ; canbitsiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORstatement want; bits to with,. other leaves iosobj; void iosobj : |)example;OR without badbit bit clear rdstate are default current cleared equals ; void of = of =: clear rdstate ;: clear bits() are; bits() error = current If can badbit cleared::and.::and.and :and.::and .all default cleared::and.::and. ::and.::and.and.bitwise clearing example changes For bit following. equals, colon error 0. default error bits equals . ( of = of :clearrdstate| with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; . ( state = 0 ) ; clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.badbit|iosobj.rdstate()); bit ( want; bits to with,. int ;iosbitwithbitsothersetsofbitsof) with,.all with,you iosobj.all with,If For0 sets: (you . and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with can bits ios bit with clearing bit ( ;voidiosobj:| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of . bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj iosobj : |)bit(OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; : clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and.and.all default cleared::and.::and.and.::and.::and.and.bitwise error clearing example changes For bit following. equals, colon error 0. changes bits ios bit with ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 , iosobj ) 0an ; been ;if 0eofbit ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during ( encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; . ( a 0 ) ; error() eofbit iosobj usually . . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an encountered : set.error(returns::if.::if.if.::if.::ifduring(.constset.()); during ( ; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually ,.an , set.an ,of nonzero0 : ( . been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during during ( EOF encountered returns during has during ( ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually . encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set during(set:) during ( when; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; : error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.: been . : : been . been . anintextraction : : been . : : been . been . : : been . : : been . been . eof iosobj hasiseofbitnonzeroduringit .ios ,ifiosobj0 . eofbitencounteredreturnsduring) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;; :valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually usually a: error ; int int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during ( encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; . ( a 0 ) ; error() eofbit iosobj usually . . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an encountered : set.error(returns::if.::if.if.::if.::ifduring(.constset.()); during ( ; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually ,.an , set.an ,of nonzero0 : ( . been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during during ( EOF encountered returns during has during ( ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually . encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set during(set:) during ( when; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; : error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.: been . : : been . been . anintextraction : : been . : : been . been . : : been . : : been . been . eof iosobj hasiseofbitnonzeroduringit .ios ,ifiosobj0 . eofbitencounteredreturnsduring) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;; :valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually usually a: error ; int int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. if failbit error nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit fail : .int(::it.::it.it.::it.error(.either.()); error ( ; fail ,. ;errorfailfail badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbiteither failbit;infailerror error(iffailerroris error(; : )set;; fail,. in; error fail . fail ;) set ; :fail) set ; returns ; state it : ; erroris error ( : )error( ; either error int const or (returnsfailnonzeroiosOtherwise;aa :int;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.: colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbit returns issetintheerrorstate .Otherwise ,itreturns0 . infailerror) ,.badbit , .badbit ,value the0 ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state :; error is ; : )set;; either error int const or returns fail nonzero ios Otherwise ; a: int ; or or failbit() either; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. , state 0. Otherwise::const.::const.const.::const.::const.const.in ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail ) set ; ;stateit:; error is ; : )set;; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon . : : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: error(.either.()); error ( ; fail ,. ;errorfailfail badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit either failbit;infailerror error(iffailerroriserror(; : )set;; fail ,. in; error fail . fail ; )set;: fail )set; returns ; state it : ; erroriserror ( : )error( ; either error int const or a :int;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. in fail error ) ,.badbit , .badbit ,value the0 ( colon)set;: ( colon)set;.badbit ,,.(: the0 : .badbit failbit ; in fail error ; if error is ; : ; ; fail ,. in; error fail fail ; ) )set;: fail )set;; state :; error is ; : )set;returns ; either error int const or returns fail nonzero ios Otherwise ; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. ,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . inreturns ) if is colon fail error badbit ios . . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail ) set ; ;stateit:; error is ; : )set;; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon . : : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: error(.either.()); error ( ; fail ,. ;errorfailfail badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit either failbit;infailerror error(iffailerroriserror(; : )set;; fail ,. in; error fail . fail ; )set;: fail )set; returns ; state it : ; erroriserror ( : )error( ; either error int const or ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof;itsstate| ) example ; without :bitsitsstate )example;; void other following colon : one in with ; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;state youcanbitwiseORthebityouwanttosetwiththecurrenterrorstate .Forexample ,thefollowingstatementsetsios : : colon : colon . colon . : : colon . : : colon . colon . badbitiniosobjandleavesalltheother bitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.: .badbit|iosobj.rdstate()); bit ( want; bits to with,. int ;iosbitwithbitsothersetsofbitsof with all with,you iosobj.all with,If For0 sets: (you . and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all badbit bitwisethewithint ;setchangesbitsiosbitwith canbitsiosbitwithclearing bit(; void iosobj : |)example;OR without statement want; bitsto ,. int changes; ios bit with bits other sets of . bits of ;itsstate| ) example ; without :bitsitsstaterdstate ) example ; error ;voidotherfollowingcolon:oneinwith; toiosbitwithclearingotherleaves iosobjiosobj:| ) bit ( ORwithout want ;intbadbitbitclearrdstatearedefaultunchanged andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobjiosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; bit ( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR error the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); . : : are . are . changes with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof;itsstate| ) example ; without :bitsitsstate )example;; void other following colon : one in with ; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;state youcanbitwiseORthebityouwanttosetwiththecurrenterrorstate .Forexample ,thefollowingstatementsetsios : : colon : colon . colon . : : colon . : : colon . colon . badbitiniosobjandleavesalltheother bitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.: ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. been ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;iosobj ;itif:valueoperation; returns during has the setduring ( set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; during ( error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof when during ( iosobj during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); . : : colon . colon . eofbit ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returnsduring(encounteredusuallyencounteredusually; state )is;: encountered state ) is ; ;itif:valueoperation; returnsduringhastheset ;set:) is ; when;Otherwiseconstduringerrorcolon iosobjencounteredinextractionios;usuallyausuallya :error;:been.::been.been.an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. EOF eof when during in iosobj . nonzero is, it returns::if :if.if.::if.::if.if.const operation set been the an encountered: set.error(returns::if.::if.if.::if.: ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 :.an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the set ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;) int eof() eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is; iosobj ; it if : value operation ; returns during has the setduring ( set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a . ( usually a: error ; during ( error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof ) when during ( iosobj during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); . : : colon . colon . eofbit is usually set when an iosobj ) EOF has been encountered during an extraction operation. . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returnsduring(encounteredusuallyencounteredusually; state )is;: encountered state ) is ; ;itif:valueoperation; returnsduringhastheset ;set:) is ; when;Otherwiseconstduringerrorcolon iosobjencounteredinextractionios;usuallyausuallya :error;:been.::been.been.an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. EOF eof when during in iosobj . nonzero is, it returns::if :if.if.::if.::if.if.const operation set been the an encountered: set.error(returns::if.::if.if.::if.: ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 :.an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the set ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;) int eof() eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. returns fail Otherwise . ( a :int 0 ,returns)0 badbit;colon; it 0 in a error :badbit ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: ) ,.badbit , .badbit ,value the0 : colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error a a: int ; ) or failbit() either failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if is colon fail error badbit ios . ) set ; . badbit , : the 0 : . badbit failbit ; in fail error error(iffailerroris;:) set ; ) ,.badbit , ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . ( . badbit , value the 0 : ( colon ) set ; : ( colon ) set ; . badbit , : the 0 : . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; it : ; error is ; : )set;; either error int const or nonzero ios Otherwise ; a a: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::. badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: ) ,.badbit , .badbit ,value the0 : colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error a a: int ; ) or failbit() either failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if is colon fail error badbit ios . ) set ; . badbit , : the 0 : . badbit failbit ; in fail error error(iffailerroris;:) set ; ) ,.badbit ,.(.badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; it : ; error is ; : )set;; either error int const or nonzero ios Otherwise ; a a: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::. badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); clear its If error. int ios 0. equals::are.::are.are.::are.::are.are.changes example of iosobj OR all can clearing and bits bit all cleared in. ) example ; . all with , you iosobj : For 0 : you . ( iosobj . all with , If For 0 sets : ( you and | ) example ; without : ( you and rdstate ) example ; . all with , you iosobj : For 0 : you . all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. changes; ios bit with bits other sets of , . ( bits of ; its state |)example;without: bits its state rdstate)example;; void colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged current cleared equals ; void of = of =: clear rdstate with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof ; its state |)example;without: bits its state ) example ; ;voidotherfollowingcolon:oneinwith; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithout want ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate; andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj :| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement , . ;intbadbitbitclearrdstatearedefaultunchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;,bit( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.:. : : colon . colon . badbitiniosobjandleavesalltheothererrorstatebitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); bit ( clear its If error. int ios 0. equals::are.::are.are.::are.::are.are.changes example of iosobj OR all can clearing and bits bit all cleared in. ) example ; . all with , you iosobj : For 0 : you can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement without ) with,.all with,you .(iosobjsets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. changes; ios bit with bits other sets of bit ( , . ( bits of ; its state |)example;without: bits its state rdstate)example;; void colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement ( want; int badbit bit clear rdstate are default unchanged current cleared equals ; void of = of =: clear rdstate ;: clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and .all default cleared::and.::and.and.::and.::and.and.bitwise clearing example changes For bit following. equals, colon error 0. default error bits equals . ( of = ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. . : . an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set during ( :) is ; when; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the ( set; set : )is;when during(,. ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; , during ( (Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it ) returns::if.::if.if.:during(.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( error state of iosobj. Otherwise returns 0. ios::colon.::colon.colon.. : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . ) is ; . an , set : nonzero 0 : set; set : )is;when ) ,.an , .(set: ( been)is;: ( been)is;.an , set: nonzero,.(: .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. eofbit; returns during encountered usually during ( , . ( encountered usually ; state )is;: encountered state )is;; if : value operation ; returns during the set; set : )is;when const during error colon int in extraction ios ; usually a usually a: error ; error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.been.::been.::been .an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. int iosobj encountered ios ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; colon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . . : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set during ( :) is ; when; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually; state )is;: encountered state )is;; it if : value operation ; returns during has the during ( , . ;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;,during( (Otherwise a0); error() eofbit iosobj usually set ( . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it ) colon set . error ( returns : : if . : : if . if . : : if . : : if . if . const set . ( ) ) ; during ( error state of iosobj. Otherwise returns 0. ios::colon.::colon.colon.: .::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : ,.an , .(set: ( been)is;: ( been)is;.an , set: nonzero0 ,.(: .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. ;state) is ; :encounteredstate) is ; ; if:valueoperation; returns during the set; set : )is;when const during error colon int in extraction ios ; usually a usually a: error ;: error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.: been . : : been . anintextraction : : been . : : been . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; colon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . . : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set during ( :) is ; when; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. in fail error error(iffailerroris;:) set ; ,.badbit , .(. : ( colon)set;: ( colon)set;.badbit , : the0 ,.(: .badbit failbit ; in fail error ;if fail error is ; : )set;; fail ,. . error ( , . ( fail ;) set ; :fail) set ; ; it:; ; : )set; either error int const or nonzero ios Otherwise ; a a: int ;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.::colon .badbit or ios::colon.::colon: : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a: int 0 ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; const . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. . : . badbit failbit ; in fail error ; if fail error is ; error ( :) set ; ; fail ,. ;errorfailfail) ,.badbit , .badbit ,value the0 : ( ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . colon ) set ; : ( colon ) set ; . badbit , : the 0 : . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. in fail error error(iffailerroris;:) set ; ,.badbit ,.( . : ( colon)set;: ( colon)set;.badbit , : the0 ,.(: .badbit failbit ; in fail error ; iffailerroris;:) set ; ; fail ,. in; error fail . error ( , . ( fail ;) set ; :fail) set ; ;it : ; ; : )set; either error int const or nonzero ios Otherwise ; a a: int ;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.::. badbitorios : : colon . : : colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; const . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. . : . badbit failbit ; in fail error ; if fail error is ; error ( :) set ; ; fail ,. ;errorfailfail) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. in fail error error(iffailerroris;:) set ; ,.badbit ,.( . : ( colon)set;: ( colon)set;.badbit , : the0 ,.(: .badbit failbit ; in fail error ; iffailerroris;:) set ; ; fail ,. in; error fail . error ( , . ( fail ;) set ; :fail) set ; ;it : ; ; : )set; either error int const or nonzero ios Otherwise ; a a: int ;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.:: ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); want; bits to with,. int ;iosbitwithbitsothersetsofbitsof) with,.all with,you iosobj.all with,If For0 sets: (you . and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing ;voidiosobj:| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of . bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj ;voidiosobj:| ) ORwithoutstatementwant ;intbadbitbitclearrdstatearedefaultunchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;: clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and.and.all default cleared::and.::and.and.::and.::and.and.bitwise error clearing example changes For bit following. equals, colon error 0. changes bits ios bit with bit(canbitsiosbitwithclearingotherleaves;voidiosobj:| ) example ; OR withoutstatement with,.all with,you .(iosobjsets . : (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 ,.(: you .all bitwise the with int; set changes bits ios bit with ; canbitsiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORstatement want; bits to with,. other leaves iosobj; void iosobj : |)example;OR without badbit bit clear rdstate are default current cleared equals ; void of = of =: clear rdstate ;: clear bits() are; bits() error = current If can badbit cleared::and.::and.and :and.::and .all default cleared::and.::and. ::and.::and.and.bitwise clearing example changes For bit following. equals, colon error 0. default error bits equals . ( of = of :clearrdstate| with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; . ( state = 0 ) ; clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.badbit|iosobj.rdstate()); bit ( want; bits to with,. int ;iosbitwithbitsothersetsofbitsof) with,.all with,you iosobj.all with,If For0 sets: (you . and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with can bits ios bit with clearing bit ( ;voidiosobj:| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of . bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj iosobj : |)bit(OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; : clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and.and.all default cleared::and.::and.and.::and.::and.and.bitwise error clearing example changes For bit following. equals, colon error 0. changes bits ios bit with ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 , iosobj ) 0an ; been ;if 0eofbit ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during ( encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; . ( a 0 ) ; error() eofbit iosobj usually . . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an encountered : set.error(returns::if.::if.if.::if.::ifduring(.constset.()); during ( ; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually ,.an , set.an ,of nonzero0 : ( . been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during during ( EOF encountered returns during has during ( ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually . encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set during(set:) during ( when; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; : error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.: been . : : been . been . anintextraction : : been . : : been . been . : : been . : : been . been . eof iosobj hasiseofbitnonzeroduringit .ios ,ifiosobj0 . eofbitencounteredreturnsduring) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;; :valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually usually a: error ; int int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during ( encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; . ( a 0 ) ; error() eofbit iosobj usually . . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an encountered : set.error(returns::if.::if.if.::if.::ifduring(.constset.()); during ( ; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually ,.an , set.an ,of nonzero0 : ( . been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during during ( EOF encountered returns during has during ( ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually . encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set during(set:) during ( when; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; : error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.: been . : : been . been . anintextraction : : been . : : been . been . : : been . : : been . been . eof iosobj hasiseofbitnonzeroduringit .ios ,ifiosobj0 . eofbitencounteredreturnsduring) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;; :valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually usually a: error ; int int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. if failbit error nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit fail : .int(::it.::it.it.::it.error(.either.()); error ( ; fail ,. ;errorfailfail badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbiteither failbit;infailerror error(iffailerroris error(; : )set;; fail,. in; error fail . fail ;) set ; :fail) set ; returns ; state it : ; erroris error ( : )error( ; either error int const or (returnsfailnonzeroiosOtherwise;aa :int;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.: colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbit returns issetintheerrorstate .Otherwise ,itreturns0 . infailerror) ,.badbit , .badbit ,value the0 ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state :; error is ; : )set;; either error int const or returns fail nonzero ios Otherwise ; a: int ; or or failbit() either; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. , state 0. Otherwise::const.::const.const.::const.::const.const.in ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail ) set ; ;stateit:; error is ; : )set;; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon . : : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: error(.either.()); error ( ; fail ,. ;errorfailfail badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit either failbit;infailerror error(iffailerroriserror(; : )set;; fail ,. in; error fail . fail ; )set;: fail )set; returns ; state it : ; erroriserror ( : )error( ; either error int const or a :int;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. in fail error ) ,.badbit , .badbit ,value the0 ( colon)set;: ( colon)set;.badbit ,,.(: the0 : .badbit failbit ; in fail error ; if error is ; : ; ; fail ,. in; error fail fail ; ) )set;: fail )set;; state :; error is ; : )set;returns ; either error int const or returns fail nonzero ios Otherwise ; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. ,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . inreturns ) if is colon fail error badbit ios . . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail ) set ; ;stateit:; error is ; : )set;; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon . : : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: error(.either.()); error ( ; fail ,. ;errorfailfail badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit either failbit;infailerror error(iffailerroriserror(; : )set;; fail ,. in; error fail . fail ; )set;: fail )set; returns ; state it : ; erroriserror ( : )error( ; either error int const or ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof;itsstate| ) example ; without :bitsitsstate )example;; void other following colon : one in with ; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;state youcanbitwiseORthebityouwanttosetwiththecurrenterrorstate .Forexample ,thefollowingstatementsetsios : : colon : colon . colon . : : colon . : : colon . colon . badbitiniosobjandleavesalltheother bitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.: .badbit|iosobj.rdstate()); bit ( want; bits to with,. int ;iosbitwithbitsothersetsofbitsof with all with,you iosobj.all with,If For0 sets: (you . and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all badbit bitwisethewithint ;setchangesbitsiosbitwith canbitsiosbitwithclearing bit(; void iosobj : |)example;OR without statement want; bitsto ,. int changes; ios bit with bits other sets of . bits of ;itsstate| ) example ; without :bitsitsstaterdstate ) example ; error ;voidotherfollowingcolon:oneinwith; toiosbitwithclearingotherleaves iosobjiosobj:| ) bit ( ORwithout want ;intbadbitbitclearrdstatearedefaultunchanged andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobjiosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; bit ( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR error the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); . : : are . are . changes with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof;itsstate| ) example ; without :bitsitsstate )example;; void other following colon : one in with ; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;state youcanbitwiseORthebityouwanttosetwiththecurrenterrorstate .Forexample ,thefollowingstatementsetsios : : colon : colon . colon . : : colon . : : colon . colon . badbitiniosobjandleavesalltheother bitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.: ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. been ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;iosobj ;itif:valueoperation; returns during has the setduring ( set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; during ( error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof when during ( iosobj during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); . : : colon . colon . eofbit ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returnsduring(encounteredusuallyencounteredusually; state )is;: encountered state ) is ; ;itif:valueoperation; returnsduringhastheset ;set:) is ; when;Otherwiseconstduringerrorcolon iosobjencounteredinextractionios;usuallyausuallya :error;:been.::been.been.an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. EOF eof when during in iosobj . nonzero is, it returns::if :if.if.::if.::if.if.const operation set been the an encountered: set.error(returns::if.::if.if.::if.: ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 :.an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the set ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;) int eof() eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is; iosobj ; it if : value operation ; returns during has the setduring ( set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a . ( usually a: error ; during ( error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof ) when during ( iosobj during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); . : : colon . colon . eofbit is usually set when an iosobj ) EOF has been encountered during an extraction operation. . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returnsduring(encounteredusuallyencounteredusually; state )is;: encountered state ) is ; ;itif:valueoperation; returnsduringhastheset ;set:) is ; when;Otherwiseconstduringerrorcolon iosobjencounteredinextractionios;usuallyausuallya :error;:been.::been.been.an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. EOF eof when during in iosobj . nonzero is, it returns::if :if.if.::if.::if.if.const operation set been the an encountered: set.error(returns::if.::if.if.::if.: ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 :.an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the set ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;) int eof() eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. returns fail Otherwise . ( a :int 0 ,returns)0 badbit;colon; it 0 in a error :badbit ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: ) ,.badbit , .badbit ,value the0 : colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error a a: int ; ) or failbit() either failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if is colon fail error badbit ios . ) set ; . badbit , : the 0 : . badbit failbit ; in fail error error(iffailerroris;:) set ; ) ,.badbit , ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . ( . badbit , value the 0 : ( colon ) set ; : ( colon ) set ; . badbit , : the 0 : . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; it : ; error is ; : )set;; either error int const or nonzero ios Otherwise ; a a: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::. badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: ) ,.badbit , .badbit ,value the0 : colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error a a: int ; ) or failbit() either failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if is colon fail error badbit ios . ) set ; . badbit , : the 0 : . badbit failbit ; in fail error error(iffailerroris;:) set ; ) ,.badbit ,.(.badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; it : ; error is ; : )set;; either error int const or nonzero ios Otherwise ; a a: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::. badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); clear its If error. int ios 0. equals::are.::are.are.::are.::are.are.changes example of iosobj OR all can clearing and bits bit all cleared in. ) example ; . all with , you iosobj : For 0 : you . ( iosobj . all with , If For 0 sets : ( you and | ) example ; without : ( you and rdstate ) example ; . all with , you iosobj : For 0 : you . all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. changes; ios bit with bits other sets of , . ( bits of ; its state |)example;without: bits its state rdstate)example;; void colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged current cleared equals ; void of = of =: clear rdstate with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof ; its state |)example;without: bits its state ) example ; ;voidotherfollowingcolon:oneinwith; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithout want ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate; andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj :| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement , . ;intbadbitbitclearrdstatearedefaultunchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;,bit( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.:. : : colon . colon . badbitiniosobjandleavesalltheothererrorstatebitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); bit ( clear its If error. int ios 0. equals::are.::are.are.::are.::are.are.changes example of iosobj OR all can clearing and bits bit all cleared in. ) example ; . all with , you iosobj : For 0 : you can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement without ) with,.all with,you .(iosobjsets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. changes; ios bit with bits other sets of bit ( , . ( bits of ; its state |)example;without: bits its state rdstate)example;; void colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement ( want; int badbit bit clear rdstate are default unchanged current cleared equals ; void of = of =: clear rdstate ;: clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and .all default cleared::and.::and.and.::and.::and.and.bitwise clearing example changes For bit following. equals, colon error 0. default error bits equals . ( of = ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. . : . an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set during ( :) is ; when; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the ( set; set : )is;when during(,. ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; , during ( (Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it ) returns::if.::if.if.:during(.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); during ( error state of iosobj. Otherwise returns 0. ios::colon.::colon.colon.. : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . ) is ; . an , set : nonzero 0 : set; set : )is;when ) ,.an , .(set: ( been)is;: ( been)is;.an , set: nonzero,.(: .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. eofbit; returns during encountered usually during ( , . ( encountered usually ; state )is;: encountered state )is;; if : value operation ; returns during the set; set : )is;when const during error colon int in extraction ios ; usually a usually a: error ; error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.been.::been.::been .an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. int iosobj encountered ios ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; colon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . . : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set during ( :) is ; when; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually; state )is;: encountered state )is;; it if : value operation ; returns during has the during ( , . ;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;,during( (Otherwise a0); error() eofbit iosobj usually set ( . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it ) colon set . error ( returns : : if . : : if . if . : : if . : : if . if . const set . ( ) ) ; during ( error state of iosobj. Otherwise returns 0. ios::colon.::colon.colon.: .::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : ,.an , .(set: ( been)is;: ( been)is;.an , set: nonzero0 ,.(: .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. ;state) is ; :encounteredstate) is ; ; if:valueoperation; returns during the set; set : )is;when const during error colon int in extraction ios ; usually a usually a: error ;: error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.: been . : : been . anintextraction : : been . : : been . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; colon . : : colon . colon . eofbitissetintheerrorstateofiosobj .Otherwise ,itreturns0 .ios : : colon . : : colon . colon . : : colon . : : colon . colon . eofbitisusuallysetwhenanEOFhasbeenencounteredduringanextractionoperation . . : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set during ( :) is ; when; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. in fail error error(iffailerroris;:) set ; ,.badbit , .(. : ( colon)set;: ( colon)set;.badbit , : the0 ,.(: .badbit failbit ; in fail error ;if fail error is ; : )set;; fail ,. . error ( , . ( fail ;) set ; :fail) set ; ; it:; ; : )set; either error int const or nonzero ios Otherwise ; a a: int ;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.::colon .badbit or ios::colon.::colon: : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a: int 0 ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; const . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. . : . badbit failbit ; in fail error ; if fail error is ; error ( :) set ; ; fail ,. ;errorfailfail) ,.badbit , .badbit ,value the0 : ( ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . colon ) set ; : ( colon ) set ; . badbit , : the 0 : . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. in fail error error(iffailerroris;:) set ; ,.badbit ,.( . : ( colon)set;: ( colon)set;.badbit , : the0 ,.(: .badbit failbit ; in fail error ; iffailerroris;:) set ; ; fail ,. in; error fail . error ( , . ( fail ;) set ; :fail) set ; ;it : ; ; : )set; either error int const or nonzero ios Otherwise ; a a: int ;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.::. badbitorios : : colon . : : colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; const . const . const . : : const . const . insetnonzerointvaluereturns .,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . insetbadbitifiscolonfailerrorbadbitios. . : . badbit failbit ; in fail error ; if fail error is ; error ( :) set ; ; fail ,. ;errorfailfail) ,.badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail . fail ; )set;: fail )set;; state it : ; error is ;:) set ; ;eithererrorintconstorreturnsfailnonzeroiosOtherwise;aa: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. in fail error error(iffailerroris;:) set ; ,.badbit ,.( . : ( colon)set;: ( colon)set;.badbit , : the0 ,.(: .badbit failbit ; in fail error ; iffailerroris;:) set ; ; fail ,. in; error fail . error ( , . ( fail ;) set ; :fail) set ; ;it : ; ; : )set; either error int const or nonzero ios Otherwise ; a a: int ;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.:: ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); want; bits to with,. int ;iosbitwithbitsothersetsofbitsof) with,.all with,you iosobj.all with,If For0 sets: (you . and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing ;voidiosobj:| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of . bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj ;voidiosobj:| ) ORwithoutstatementwant ;intbadbitbitclearrdstatearedefaultunchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;: clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and.and.all default cleared::and.::and.and.::and.::and.and.bitwise error clearing example changes For bit following. equals, colon error 0. changes bits ios bit with bit(canbitsiosbitwithclearingotherleaves;voidiosobj:| ) example ; OR withoutstatement with,.all with,you .(iosobjsets . : (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 ,.(: you .all bitwise the with int; set changes bits ios bit with ; canbitsiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORstatement want; bits to with,. other leaves iosobj; void iosobj : |)example;OR without badbit bit clear rdstate are default current cleared equals ; void of = of =: clear rdstate ;: clear bits() are; bits() error = current If can badbit cleared::and.::and.and :and.::and .all default cleared::and.::and. ::and.::and.and.bitwise clearing example changes For bit following. equals, colon error 0. default error bits equals . ( of = of :clearrdstate| with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with ; can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; . ( state = 0 ) ; clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.badbit|iosobj.rdstate()); bit ( want; bits to with,. int ;iosbitwithbitsothersetsofbitsof) with,.all with,you iosobj.all with,If For0 sets: (you . and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with can bits ios bit with clearing bit ( ;voidiosobj:| ) example ; ORwithoutstatementwant ; bits to with,. int changes; ios bit with bits other sets of . bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobj iosobj : |)bit(OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; : clear bits() are; bits() error = current If can badbit cleared::and.::and.and.::and.::and.and.all default cleared::and.::and.and.::and.::and.and.bitwise error clearing example changes For bit following. equals, colon error 0. changes bits ios bit with ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 , iosobj ) 0an ; been ;if 0eofbit ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during ( encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; . ( a 0 ) ; error() eofbit iosobj usually . . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an encountered : set.error(returns::if.::if.if.::if.::ifduring(.constset.()); during ( ; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually ,.an , set.an ,of nonzero0 : ( . been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during during ( EOF encountered returns during has during ( ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually . encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set during(set:) during ( when; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; : error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.: been . : : been . been . anintextraction : : been . : : been . been . : : been . : : been . been . eof iosobj hasiseofbitnonzeroduringit .ios ,ifiosobj0 . eofbitencounteredreturnsduring) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;; :valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually usually a: error ; int int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ;EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during ( encountered usually encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; . ( a 0 ) ; error() eofbit iosobj usually . . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has encountered operation iosobj , EOF eof when during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an encountered : set.error(returns::if.::if.if.::if.::ifduring(.constset.()); during ( ; encountered ,. Otherwise ;returnsduringencounteredusuallyencounteredusually ,.an , set.an ,of nonzero0 : ( . been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during during ( EOF encountered returns during has during ( ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually . encountered usually ;state) is ; :encounteredstate) is ; ;itif:valueoperation; returns during has the set during(set:) during ( when; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; : error encountered() colon; encountered() iosobj a in of EOF const extraction::been.::been.: been . : : been . been . anintextraction : : been . : : been . been . : : been . : : been . been . eof iosobj hasiseofbitnonzeroduringit .ios ,ifiosobj0 . eofbitencounteredreturnsduring) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : .an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;; :valueoperation; returns during has the set; set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually usually a: error ; int int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. if failbit error nonzero returns . the set, state ::it.::it.it.::it.::it.it.either colon badbit fail : .int(::it.::it.it.::it.error(.either.()); error ( ; fail ,. ;errorfailfail badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbiteither failbit;infailerror error(iffailerroris error(; : )set;; fail,. in; error fail . fail ;) set ; :fail) set ; returns ; state it : ; erroris error ( : )error( ; either error int const or (returnsfailnonzeroiosOtherwise;aa :int;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.: colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbit returns issetintheerrorstate .Otherwise ,itreturns0 . infailerror) ,.badbit , .badbit ,value the0 ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state :; error is ; : )set;; either error int const or returns fail nonzero ios Otherwise ; a: int ; or or failbit() either; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. , state 0. Otherwise::const.::const.const.::const.::const.const.in ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail ) set ; ;stateit:; error is ; : )set;; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon . : : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: error(.either.()); error ( ; fail ,. ;errorfailfail badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit either failbit;infailerror error(iffailerroriserror(; : )set;; fail ,. in; error fail . fail ; )set;: fail )set; returns ; state it : ; erroriserror ( : )error( ; either error int const or a :int;: int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon :colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.returns is set in the error state. Otherwise, it returns 0. in fail error ) ,.badbit , .badbit ,value the0 ( colon)set;: ( colon)set;.badbit ,,.(: the0 : .badbit failbit ; in fail error ; if error is ; : ; ; fail ,. in; error fail fail ; ) )set;: fail )set;; state :; error is ; : )set;returns ; either error int const or returns fail nonzero ios Otherwise ; failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. ,state0 .Otherwise : : const . : : const . const . : : const . : : const . const . inreturns ) if is colon fail error badbit ios . . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail ) set ; ;stateit:; error is ; : )set;; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon . : : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: error(.either.()); error ( ; fail ,. ;errorfailfail badbit , .badbit ,value the0 : ( . colon)set;: ( colon)set;.badbit , : the0 : .badbit either failbit;infailerror error(iffailerroriserror(; : )set;; fail ,. in; error fail . fail ; )set;: fail )set; returns ; state it : ; erroriserror ( : )error( ; either error int const or ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof;itsstate| ) example ; without :bitsitsstate )example;; void other following colon : one in with ; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;state youcanbitwiseORthebityouwanttosetwiththecurrenterrorstate .Forexample ,thefollowingstatementsetsios : : colon : colon . colon . : : colon . : : colon . colon . badbitiniosobjandleavesalltheother bitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.: .badbit|iosobj.rdstate()); bit ( want; bits to with,. int ;iosbitwithbitsothersetsofbitsof with all with,you iosobj.all with,If For0 sets: (you . and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you .all badbit bitwisethewithint ;setchangesbitsiosbitwith canbitsiosbitwithclearing bit(; void iosobj : |)example;OR without statement want; bitsto ,. int changes; ios bit with bits other sets of . bits of ;itsstate| ) example ; without :bitsitsstaterdstate ) example ; error ;voidotherfollowingcolon:oneinwith; toiosbitwithclearingotherleaves iosobjiosobj:| ) bit ( ORwithout want ;intbadbitbitclearrdstatearedefaultunchanged andrdstate)example;.all with,you iosobj: For0 : you .all bitwise the with int; set changes bits ios bit with can bits ios bit with clearing other leaves iosobj; void iosobj : |)example;OR without statement want; bits to with,. int changes; ios bit with bits other sets of bits of ; its state |)example;without: bits its state rdstate)example;; void other following colon : one in with ; to ios bit with clearing other leaves iosobjiosobj : |)example;OR without statement want; int badbit bit clear rdstate are default unchanged error bits current cleared equals ; void of = of =: clear rdstate ; bit ( void clear(int state=0); clear() changes the error state of iosobj to state. If state equals 0 (its default), all of the bits in the error state are cleared. If you want to set one of the bits without clearing the other bits in the error state, you can bitwise OR error the bit you want to set with the current error state. For example, the following statement sets ios::colon.::colon.colon.::colon.::colon.colon.badbit in iosobj and leaves all the other error state bits unchanged: iosobj.clear(ios::colon.::colon.colon.::colon.::colon.colon.badbit|iosobj.rdstate()); . : : are . are . changes with,.all with,you iosobj.all with,If For0 sets: (you and|)example;without: (you andrdstate)example;.all with,you iosobj: For0 : you with , .intchanges ;iosbitsothersetsofbitsof;itsstate| ) example ; without :bitsitsstate )example;; void other following colon : one in with ; toiosbitwithclearingotherleavesiosobj ;voidiosobj:| ) example ; ORwithoutstatementwant ;intbadbitbitclearrdstateare unchangederrorbitscurrentclearedequals;voidof=of= :clearrdstate;state youcanbitwiseORthebityouwanttosetwiththecurrenterrorstate .Forexample ,thefollowingstatementsetsios : : colon : colon . colon . : : colon . : : colon . colon . badbitiniosobjandleavesalltheother bitsunchanged : iosobj.clear(ios::colon.::colon.colon.::colon.: ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int eof() const; eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. been ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is;iosobj ;itif:valueoperation; returns during has the setduring ( set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a usually a: error ; during ( error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof when during ( iosobj during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); . : : colon . colon . eofbit ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returnsduring(encounteredusuallyencounteredusually; state )is;: encountered state ) is ; ;itif:valueoperation; returnsduringhastheset ;set:) is ; when;Otherwiseconstduringerrorcolon iosobjencounteredinextractionios;usuallyausuallya :error;:been.::been.been.an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. EOF eof when during in iosobj . nonzero is, it returns::if :if.if.::if.::if.if.const operation set been the an encountered: set.error(returns::if.::if.if.::if.: ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 :.an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the set ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;) int eof() eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when ; encountered ,. Otherwise eofbit; returns during encountered usually encountered usually ; state )is;: encountered state )is; iosobj ; it if : value operation ; returns during has the setduring ( set : )is;when ; Otherwise const during error colon int iosobj encountered in extraction ios ; usually a . ( usually a: error ; during ( error(Otherwise a0); error() eofbit iosobj usually set . of ios 0 (state int), an usually encountered operation iosobj colon extraction. of value usually encountered has iosobj , EOF eof ) when during ( iosobj during in iosobj . nonzero is, it returns::if.::if.if.::if.::if.if.const operation set been the an iosobj encountered : set.error(returns::if.::if.if.::if.::if.if.constset.()); . : : colon . colon . eofbit is usually set when an iosobj ) EOF has been encountered during an extraction operation. . been . : : been . : : been . been . eofhasiseofbitnonzeroduringit .ios ,ifiosobj0 .int iosobjencountered ios .(usuallyausually: error 0 ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 : ; EOF encountered returns during has the set; set : )is;when ; encountered , .Otherwiseeofbit ;returnsduring(encounteredusuallyencounteredusually; state )is;: encountered state ) is ; ;itif:valueoperation; returnsduringhastheset ;set:) is ; when;Otherwiseconstduringerrorcolon iosobjencounteredinextractionios;usuallyausuallya :error;:been.::been.been.an int extraction::been.::been.been.::been.::been.been.eof has is eofbit nonzero during it. ios, if iosobj 0. EOF eof when during in iosobj . nonzero is, it returns::if :if.if.::if.::if.if.const operation set been the an encountered: set.error(returns::if.::if.if.::if.: ) ,.an , set.an ,of nonzero0 : ( been)is;: ( been)is;.an , set: nonzero0 :.an eof Otherwise; eofbit encountered returns during ; EOF encountered returns during has the set; set : )is;when ; encountered ,. Otherwise eofbit; during encountered usually encountered usually ; state )is;: encountered state )is;; it if : value operation ; returns during has the set ;set:) is ; when;Otherwiseconstduringerrorcolonintiosobjencounteredinextractionios;usuallyausuallya :error;) int eof() eof() returns a nonzero value if ios::colon.::colon.colon.::colon.::colon.colon.eofbit is set in the error state of iosobj. Otherwise, it returns 0. ios::colon.::colon.colon.::colon.::colon.colon.eofbit is usually set when an EOF has been encountered during an extraction operation. ) is ; . an , set : nonzero 0 : . an eof Otherwise; eofbit encountered returns during during(EOFencounteredreturnsduringhastheset ;set:) is ; when ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot be opened, the error state of the constructed ifstream object is set. The fourth version constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. This constructor also sets up an associated filebuf object with a stream buffer that has length len bytes and begins at the position pointed to by p. If p is equal to 0 or len is equal to 0, the associated filebuf object is unbuffered. int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::colon.colon.badbit or ios::colon.::colon.colon.::colon.::colon.colon.failbit is set in the error state. Otherwise, it returns 0. returns fail Otherwise . ( a :int 0 ,returns)0 badbit;colon; it 0 in a error :badbit ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: ) ,.badbit , .badbit ,value the0 : colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error a a: int ; ) or failbit() either failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if is colon fail error badbit ios . ) set ; . badbit , : the 0 : . badbit failbit ; in fail error error(iffailerroris;:) set ; ) ,.badbit , ═══ <hidden> n.colon.::colon.::colon.colon.failbit and ios::colon.::co ═══ . ( . badbit , value the 0 : ( colon ) set ; : ( colon ) set ; . badbit , : the 0 : . badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; it : ; error is ; : )set;; either error int const or nonzero ios Otherwise ; a a: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::. badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; : colon . colon : colon . : : colon . colon . badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 . iffailbiterrornonzeroreturns.theset ,state: : : it . it . : : it . : : it . it . eithercolonbadbit fail: .int(::it.::it.it.::it.: ) ,.badbit , .badbit ,value the0 : colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; state it : ; error a a: int ; ) or failbit() either failbit() a the it Otherwise::const.::const.const.::const.::const.const.in set nonzero int value returns. 0. Otherwise::const.::const.const.::const.::const.const.in set badbit if is colon fail error badbit ios . ) set ; . badbit , : the 0 : . badbit failbit ; in fail error error(iffailerroris;:) set ; ) ,.badbit ,.(.badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ; if fail error is ; : )set;; fail ,. in; error fail fail ; )set;: fail )set;; it : ; error is ; : )set;; either error int const or nonzero ios Otherwise ; a a: int ; : int fail() const; fail() returns a nonzero value if either ios::colon.::colon.colon.::colon.::. badbitorios : : colon . : : colon . colon . : : colon . : : colon . colon . failbitissetintheerrorstate .Otherwise ,itreturns0 .or returnsfail Otherwise .(a ,.badbit , .badbit ,value the0 : ( colon)set;: ( colon)set;.badbit , : the0 : .badbit failbit ; in fail error ;iffailerroris;:) set ; ; fail ,. in; error ( fail fail ;) set ; :fail) set ; ;stateit:; error is ; : )set; ; either error int returns fail nonzero ios Otherwise ; a a: int ; ifstream(); ifstream(int d); ifstream(const char* fname, int mode=ios&c2.in, int prot=filebuf&c2.openprot); ifstream(int d, char* p, int len); There are four versions of the ifstream constructor. The first version takes no arguments and constructs an unopened ifstream object. The second version takes one argument and constructs an ifstream object that is attached to the file descriptor d. If d is not open, ios&c2.failbit is set in the format state of ifs. The third and fourth versions of the ifstream() constructor take three arguments. The third version constructs an ifstream object and opens the file fname with open mode equal to mode and protection mode equal to prot. The default value for mode is ios&c2.in, and the default value for prot is filebuf&c2.openprot. If the file cannot