次の方法で共有


Input Streams

 

Visual C++ in Visual Studio 2015

The latest version of this topic can be found at Input Streams.

An input stream object is a source of bytes. The three most important input stream classes are istream, ifstream, and istringstream.

The istream class is best used for sequential text-mode input. You can configure objects of class istream for buffered or unbuffered operation. All functionality of the base class, ios, is included in istream. You will rarely construct objects from class istream. Instead, you will generally use the predefined cin object, which is actually an object of class ostream. In some cases, you can assign cin to other stream objects after program startup.

The ifstream class supports disk file input. If you need an input-only disk file, construct an object of class ifstream. You can specify binary or text-mode data. If you specify a filename in the constructor, the file is automatically opened when the object is constructed. Otherwise, you can use the open function after invoking the default constructor. Many formatting options and member functions apply to ifstream objects. All functionality of the base classes ios and istream is included in ifstream.

Like the library function sscanf_s, the istringstream class supports input from in-memory strings. To extract data from a character array that has a null terminator, allocate and initialize the string, then construct an object of class istringstream.

In This Section

Constructing Input Stream Objects

Using Extraction Operators

Testing for Extraction Errors

Input Stream Manipulators

Input Stream Member Functions

Overloading the >> Operator for Your Own Classes

See Also

iostream Programming