The setprecision manipulator cannot be used to format data written to a file. ✅ Đầy đủ
Kinh Nghiệm về The setprecision manipulator cannot be used to format data written to a file. Chi Tiết
Lê Hoàng Hưng đang tìm kiếm từ khóa The setprecision manipulator cannot be used to format data written to a file. được Update vào lúc : 2022-12-20 19:50:12 . Với phương châm chia sẻ Bí kíp Hướng dẫn trong nội dung bài viết một cách Chi Tiết 2022. Nếu sau khi tham khảo nội dung bài viết vẫn ko hiểu thì hoàn toàn có thể lại phản hồi ở cuối bài để Admin lý giải và hướng dẫn lại nha.The C language did not build the input/output facilities into the language. In other words, there is no keyword like read or write. Instead, it left the IO to the compiler as external library functions (such as printf and
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 0 in typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 1 library). The ANSI C standard formalized these IO functions into Standard IO package (typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 2). C++ continues this approach and formalizes IO in libraries such as typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 3 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 4. Nội dung chính Show- File Input/Output (Header)String StreamsWhich class can be used to create files that can be written to but not read from C++?What data type or class is used to open existing files and read data from them into memory?Which statement opens a file for appending quizlet?Which of the following positions the file pointer for a file that has been opened for reading and writing?
- C++ IO is type safe. IO operations are defined for each of the type. If IO operations are not defined for a particular type, compiler will generate an error.C++ IO operations are based on streams of bytes and are device independent. The same set of operations can be applied to different types of IO devices.
Stream IO
C/C++ IO are based on streams, which are sequence of bytes flowing in and out of the programs (just like water and oil flowing through a pipe). In input operations, data bytes flow from an input source (such as keyboard, file, network or another program) into the program. In output operations, data bytes flow from the program to an output sink (such as console, file, network or another program). Streams acts as an intermediaries between the programs and the actual IO devices, in such the way that frees the programmers from handling the actual devices, so as to archive device independent IO operations.

C++ provides both the formatted and unformatted IO functions. In formatted or high-level IO, bytes are grouped and converted to types such as
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 5, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 6, string or user-defined types. In unformatted or low-level IO, bytes are treated as raw bytes and unconverted. Formatted IO operations are supported via overloading the stream insertion (typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7) and stream extraction (typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 8) operators, which presents a consistent public IO interface.To perform input and output, a C++ program:
Construct a stream object.Connect (Associate) the stream object to an actual IO device (e.g., keyboard, console, file, network, another program).Perform input/output operations on the stream, via the functions defined in the stream's pubic interface in a device independent manner. Some functions convert the data between the external format and internal format (formatted IO); while other does not (unformatted or binary IO).Disconnect (Dissociate) the stream to the actual IO device (e.g., close the file).Free the stream object.C++ IO Headers, Templates and ClassesHeadersC++ IO is provided in headers
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 (which included typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9), typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 (for file IO), and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 (for string IO). Furthermore, the header typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 provided manipulators such as cout << value; cin >> variable;7, cout << value; cin >> variable;8cout << value; cin >> variable;9 and cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;0 for formatting.
In order to support various character sets (
cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;1 and cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;2 in C++98/03; and cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;3, cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;4 introduced in C++11), the stream classes are written as template classes, which could be instantiated with an actual character type. Most of the template classes take two type parameters. For example,template > class basic_istream; template > class basic_ostream;where:
- cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;5 is the character type, such as cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;1 or cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;2;cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;8, of another template class cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;9, defined the properties of the character operations such as the collating sequence (sorting order) of character set.
As mention, the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 340 template classes can be instantiated with a character type, such as cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;1 and cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;2. C++ further provides 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 343 statements to name these classes:typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; Specialization Classes for char typeWe shall focus on the specialization classes for
cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;1 type:- 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
345 and 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
346: superclasses to maintain common stream properties such as format flag, field width, precision and locale. The superclass 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
345 (which is not a template class) maintains data that is independent of the template parameters; whereas the subclass 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
346 (instantiation of template 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
349) maintains data which is dependent of the template parameters.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
370 (1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
371), 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
372 (1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
373): provide the input and output public interfaces.typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
3 (1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
375): subclass of both 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
370 and 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
372, which supports bidirectional input and output operations. Take note that 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
370 and 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
372 are unidirectional streams; whereas typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
3 is bidirectional. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
375 template and typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
3 class is declared in the typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 header, not typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 header.typedef basic_istringstream istringstream;
typedef basic_ostringstream ostringstream;5, typedef basic_istringstream istringstream;
typedef basic_ostringstream ostringstream;6 and typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
4: for file input, output and bidirectional input/output.typedef basic_istringstream istringstream;
typedef basic_ostringstream ostringstream;8, typedef basic_istringstream istringstream;
typedef basic_ostringstream ostringstream;9 and read0: for read1 buffer input, output and bidirectional input/output.read2, read3 and read4: provide memory buffer for the stream, file-stream and string-stream, and the public interface for accessing and managing the buffer.
[TODO]
TheHeader and the Standard Stream Objects: cin, cout, cerr and clogThe
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 header also included the these headers: typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9. Hence, your program needs to include only the typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 header for IO operations.The
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 header declares these standard stream objects:write2 (of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 370 class, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 371 specialization), write5 (of write6 class, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 371 specialization): corresponding to the standard input stream, defaulted to keyword.write8 (of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 class), printf0 (of printf1 class): corresponding to the standard output stream, defaulted to the display console.printf2 (of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 class), printf4 (of printf1 class): corresponding to the standard error stream, defaulted to the display console.printf6 (of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 class), printf8 (of printf1 class): corresponding to the standard log stream, defaulted to the display console.The Stream Insertion << and Stream Extraction >> OperatorsFormatted output is carried out on streams via the stream insertion
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7 and stream extraction typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 8 operators. For example,cout << value; cin >> variable;Take note that write2/write8 shall be the left operand and the data flow in the direction of the arrows.
The
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 8 operators are overloaded to handle fundamental types (such as typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 5 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 6), and classes (such as read1). You can also overload these operators for your own user-defined types.The
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 09 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 10 return a reference to write2 and write8, and thus, support cascading operations. For example,cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;The ostream ClassThe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 class is a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 343 to 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 373. It contains two set of output functions: formatted output and unformatted output.- The formatted output functions (via overloaded stream insertion operator typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
7) convert numeric values (such as typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
5, typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
6) from their internal representations (e.g., 16-/32-bit typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
5, 64-bit typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
6) to a stream of characters that representing the numeric values in text form.The unformatted output functions (e.g., typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
21, typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
22) outputs the bytes as they are, without format conversion.
The
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 class overloads the stream insertion typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7 operator for each of the C++ fundamental types (cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;1, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 26, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 27, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 28, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 29, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 5, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 31, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 32, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 33, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 34 (C++11), typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 35 (C++11), typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 36, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 6 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 38. It converts a numeric value from its internal representation to the text form.The
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7 operator returns a reference to the invoking 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 object. Hence, you can concatenate typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7 operations, e.g., typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 42.The
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7 operator is also overloaded for the following pointer types:- typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
44, typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
45, typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
46: for outputting C-strings and literals. It uses the terminating null character to decide the end of the cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;1 array.typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
48: can be used to print an address.
For example,
Flushing the Output BufferYou can flush the output buffer via:
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 49 thành viên function or manipulator:typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 50 manipulator, which inserts a newline and flush the buffer. Outputting a newline character typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 51 may not flush the output buffer; but typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 50 does.write2: output buffer is flushed when input is pending, e.g.,The istream classSimilar to the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 class, the 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 370 class is a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 343 to 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 371. It also supports formatted input and unformatted input.- In formatting input, via overloading the typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
8 extraction operator, it converts the text form (a stream of character) into internal representation (such as 16-/32-bit typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
5, 64-byte typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
6).In unformatting input, such as typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
61, typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
62, typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
63, it reads the characters as they are, without conversion.
The
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 370 class overloads the extraction typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 8 operator for each of the C++ fundamental types (cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;1, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 26, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 27, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 28, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 29, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 5, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 31, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 32, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 33, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 34 (C++11), typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 35 (C++11), typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 36, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 6 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 38. It performs formatting by converting the input texts into the internal representation of the respective types.The
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 8 operator returns a reference to the invokind 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 370 object. Hence, you can concatenate typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 8 operations, e.g., typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 83.The
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 8 operator is also overloaded for the following pointer types:- typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
44, typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
45, typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
46: for inputting C-strings. It uses whitespace as delimiter and adds a terminating null character to the C-string.
[TODO] Read "C-string input".
Flushing the Input Buffer - ignore()You can use the
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 88 to discard characters in the input buffer:Unformatted Input/Output Functionsput(), get() and getline()The
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372's thành viên function typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 21 can be used to put out a cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;1. typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 21 returns the invoking 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 reference, and thus, can be cascaded. For example,[TODO] Example
read(), write() and gcount()Other istream functions - peek() and putback()States of streamThe steam superclass
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 345 maintains a data thành viên to describe the states of the stream, which is a bitmask of the type typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 95. The flags are:- typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
96: set when an input operation reaches end-of-file.typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
97: The last input operation failed to read the expected characters or output operation failed to write the expected characters, e.g., typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
98 reads n characters without reaching delimiter character.typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
99: serious error due to failure of an IO operation (e.g. file read/write error) or stream buffer.cout << value;
cin >> variable;00: Absence of above error with value of 0.
These flags are defined as public static members in
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 345. They can be accessed directly via cout << value; cin >> variable;02 or via subclasses such as cout << value; cin >> variable;03, cout << value; cin >> variable;04. However, it is more convenience to use these public thành viên functions of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 346 class:- cout << value;
cin >> variable;06: returns cout << value;
cin >> variable;07 if cout << value;
cin >> variable;00 is set (i.e., no error).cout << value;
cin >> variable;09: returns cout << value;
cin >> variable;07 if typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
96 is set.cout << value;
cin >> variable;12: returns cout << value;
cin >> variable;07 if typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
97 or typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
99 is set.cout << value;
cin >> variable;16: returns cout << value;
cin >> variable;07 if typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
99 is set.cout << value;
cin >> variable;19: clear typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
96, typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
97 and typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
99.
C++ provides a set of manipulators to perform input and output formatting:
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 header: cout << value; cin >> variable;7, cout << value; cin >> variable;8, cout << value; cin >> variable;26, cout << value; cin >> variable;9.typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 header: cout << value; cin >> variable;29, cout << value; cin >> variable;30, cout << value; cin >> variable;31, etc.Default Output FormattingThe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372's typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7 stream insertion operator is overloaded to convert a numeric value from its internal representation (e.g., 16-/32-bit typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 5, 64-bit typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 6) to the text form.- By default, the values are displayed with a field-width just enough to hold the text, without additional leading or trailing spaces. You need to provide spaces between the values, if desired.For integers, all digits will be displayed, by default. For example,For floating-point numbers, the default precison is 6 digits, except that the trailing zeros will not be shown. This default precision (of 6 digits) include all digits before and after the decimal point, but exclude the leading zeros. Scientific notation (E-notation) will be used if the exponent is 6 or more or -5 or less. In scientific notation, the default precision is also 6 digits; the exponent is displayed in 3 digits with plus/minus sign (e.g., +006, -005). For example,cout << value;
cin >> variable;36 values are displayed as 0 or 1 by default, instead of cout << value;
cin >> variable;07 or cout << value;
cin >> variable;38.
The
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 345 superclass (included in typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 header) maintains data members for field-width (cout << value; cin >> variable;41) and formatting flags (cout << value; cin >> variable;42); and provides thành viên functions (such as cout << value; cin >> variable;43, cout << value; cin >> variable;44) for manipulating them.However, it is more convenience to use the so-called IO manipulators, which returns a reference to the invoking stream object and thus can be concatenated in
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7 operator (e.g., cout << value; cin >> variable;46). They are:- cout << value;
cin >> variable;7 manipulator (in typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 header) to set the field width.cout << value;
cin >> variable;49 manipulator (in typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 header) to set the fill charactercout << value;
cin >> variable;51 manipulator (in typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 header) to set the text alignment.
The default field-width is 0, i.e., just enough space to display the value. C++ never truncates data, and will expand the field to display the entire value if the field-width is too small. The
cout << value; cin >> variable;7 operation is non-sticky. That is, it is applicable only to the next IO operation, and reset back to 0 after the operation. The field-width property is applicable to both output and input operations.Except
cout << value; cin >> variable;7, all the other IO manipulators are sticky, i.e., they take effect until a new value is set.Example: Alignment
The
cout << value; cin >> variable;55 alignment left-align the sign, but right-align the number, as illustrated.[TODO] Example of field-width for input operations
You can also use
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372's thành viên function cout << value; cin >> variable;43 (e.g. cout << value; cin >> variable;58) to set the field width, but cout << value; cin >> variable;43 cannot be used with cout << value; cin >> variable;60 operator.Floating-point Format (fixed|scientific) and Precision (setprecision)The IO stream superclass
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 345 also maintains data thành viên for the floating-point precision and display format; and provides thành viên functions (such as cout << value; cin >> variable;62) for manipulating them.Again, it is more convenience to use IO manipulators, which can be concatenated in
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7. They are:- cout << value;
cin >> variable;8 manipulator (in typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 header) to set the precision of floating-point number.cout << value;
cin >> variable;66 manipulators (in typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 header) to set the floating-point display format.
Floating point number can be display in 3 formatting modes:
cout << value; cin >> variable;68cout << value; cin >> variable;69. The precision is interpreted differently in default and non-default modes (due to legacy).- In default mode (neither cout << value;
cin >> variable;70 nor cout << value;
cin >> variable;71 used), a floating-point number is displayed in fixed-point notation (e.g., cout << value;
cin >> variable;72) for exponent in the range of cout << value;
cin >> variable;73; and scientific notation (e.g., cout << value;
cin >> variable;74) otherwise. The precision in default mode includes digits before and after the decimal point but exclude the leading zeros. Fewer digits might be shown as the trailing zeros are not displayed. The default precision is 6. See the earlier examples for default mode with default precision of 6.
As mentioned, the trailing zeros are not displayed in default mode, you can use manipulator cout << value; cin >> variable;75 to show or hide the trailing zeros.In both cout << value; cin >> variable;70 (e.g., cout << value; cin >> variable;72) and cout << value; cin >> variable;71 (e.g., cout << value; cin >> variable;74), the precision sets the number of digits after decimal point. The default precision is also 6.
For examples,
You can also use
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372's thành viên function cout << value; cin >> variable;81 (e.g. cout << value; cin >> variable;82) to set the floating-point precision, but cout << value; cin >> variable;62 cannot be used with cout << value; cin >> variable;60 operator.Integral Number Base (dec|oct|hex, setbase)C++ support number bases (radixes) of decimal, hexadecimal and octal. You can use the following manipulators (defined in
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 345 class, included in typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 header) to manipulate the integral number base:- cout << value;
cin >> variable;87: Set the integral number base. Negative cout << value;
cin >> variable;88 and cout << value;
cin >> variable;89 are displayed in 2's complement format. Alternatively, you can use cout << value;
cin >> variable;90 (in header typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9).cout << value;
cin >> variable;92: write cout << value;
cin >> variable;88 values with cout << value;
cin >> variable;94 prefix; and cout << value;
cin >> variable;89 values with cout << value;
cin >> variable;96 prefix.cout << value;
cin >> variable;97: write positive cout << value;
cin >> variable;98 value with + sign.cout << value;
cin >> variable;99: write uppercase in certain insertion operations, e.g., hex digits. It does not convert characters or strings to uppercase!
These manipulators are sticky.
For examples,
bool values (boolalpha|noboolalpha)- cout << value;
cin >> variable;31: read/write bool value as alphabetic string cout << value;
cin >> variable;07 or cout << value;
cin >> variable;38.
- cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;03: skip leading white spaces for certain input operations.cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;04: flush output after each insertion operation.
- You need to include the typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 header for cout << value;
cin >> variable;7, cout << value;
cin >> variable;8, cout << value;
cin >> variable;9, and cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;0.You can use 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
345's (in typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 header) thành viên functions cout << value;
cin >> variable;44 and cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;13 to set the individual formatting flags. However, they are not as user-friendly as using manipulators as discussed above. Furthermore, they cannot be used with cout << value;
cin >> variable;60 operator.
[TODO]
File Input/Output (Header)
C++ handles file IO similar to standard IO. In header
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9, the class typedef basic_istringstream istringstream; typedef basic_ostringstream ostringstream;6 is a subclass of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372; typedef basic_istringstream istringstream; typedef basic_ostringstream ostringstream;5 is a subclass of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 370; and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 4 is a subclass of typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 3 for bi-directional IO. You need to include both typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 headers in your program for file IO.To write to a file, you construct a
cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;24 object connecting to the output file, and use the 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 functions such as stream insertion typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 21 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 22. Similarly, to read from an input file, construct an typedef basic_istringstream istringstream; typedef basic_ostringstream ostringstream;5 object connecting to the input file, and use the 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 370 functions such as stream extraction typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 8, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 61, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 98 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 63.File IO requires an additional step to connect the file to the stream (i.e., file open) and disconnect from the stream (i.e., file close).
File OutputThe steps are:
Construct an 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 object.Connect it to a file (i.e., file open) and set the mode of file operation (e.g, truncate, append).Perform output operation via insertion typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 8 operator or typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 22, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 21 functions.Disconnect (close the file which flushes the output buffer) and không lấy phí the 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372 object.By default, opening an output file creates a new file if the filename does not exist; or truncates it (clear its content) and starts writing as an empty file.
open(), close() and is_open()File ModesFile modes are defined as static public thành viên in
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 345 superclass. They can be referenced from 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 345 or its subclasses - we typically use subclass 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 346. The available file mode flags are:cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;43 - open file for input operationcout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;44 - open file for output operationcout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;45 - output appends the end of the file.cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;46 - truncate the file and discard old contents.cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;47 - for binary (raw byte) IO operation, instead of character-based.cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;48 - position the file pointer " the end" for input/output.You can set multiple flags via bit-or (
cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;49) operator, e.g., cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;50 to append output the end of the file.For output, the default is
cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;51. For input, the default is cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;52.The steps are:
Construct an 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 370 object.Connect it to a file (i.e., file open) and set the mode of file operation.Perform output operation via extraction typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 7 operator or typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 63, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 61, typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 98 functions.Disconnect (close the file) and không lấy phí the 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 370 object.By default, opening an input file ....
Example on Simple File IO1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34Program Notes:
- Most of the typedef basic_ios ios;
typedef basic_ios wios;
typedef basic_istream istream;
typedef basic_istream wistream;
typedef basic_ostream ostream;
typedef basic_ostream wostream;
typedef basic_iostream iostream;
typedef basic_iostream wiostream;
typedef basic_streambuf streambuf;
typedef basic_streambuf wstreambuf;
9 functions (such as constructors, cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;60) supports filename in C-string only. You may need to extract the C-string from read1 object via the cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;62 thành viên function.You could use cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;63 to check if the file is opened successfully.The cout << value1 << value2 << .... ;
cin >> variable1 << variable2 << .... ;64 function returns a null pointer (converted to cout << value;
cin >> variable;38) when it reaches end-of-file.
We need to use
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 63 and typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 22 thành viên functions for binary file (file mode of cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;68), which read/write raw bytes without interpreting the bytes.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37Random Access FileRandom access file is associated with a file pointer, which can be moved directly to any location in the file. Random access is crucial in certain applications such as databases and indexes.
You can position the input pointer via
cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;69 and output pointer via cout << value1 << value2 << .... ; cin >> variable1 << variable2 << .... ;70. Each of them has two versions: absolute and relative positioning.Random access file is typically process as binary file, in both input and output modes.
[TODO] Example
String Streams
C++ provides a
typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 9 header, which uses the same public interface to support IO between a program and read1 object (buffer).The string streams is based on
typedef basic_istringstream istringstream; typedef basic_ostringstream ostringstream;9 (subclass of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 372), typedef basic_istringstream istringstream; typedef basic_ostringstream ostringstream;8 (subclass of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 370) and bi-directional read0 (subclass of typedef basic_ios ios; typedef basic_ios wios; typedef basic_istream istream; typedef basic_istream wistream; typedef basic_ostream ostream; typedef basic_ostream wostream; typedef basic_iostream iostream; typedef basic_iostream wiostream; typedef basic_streambuf streambuf; typedef basic_streambuf wstreambuf; 3).