You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/standard-library/binary-output-files.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ int main( )
21
21
}
22
22
```
23
23
24
-
You might expect this program to output the byte sequence { 99, 0, 10, 0 }; instead, it outputs { 99, 0, 13, 10, 0 }, which causes problems for a program expecting binary input. If you need true binary output, in which characters are written untranslated, you could specify binary output by using the [ofstream](../standard-library/basic-ofstream-class.md#basic_ofstream) constructor openmode argument:
24
+
You might expect this program to output the byte sequence { 99, 0, 10, 0 }; instead, it outputs { 99, 0, 13, 10, 0 }, which causes problems for a program expecting binary input. If you need true binary output, in which characters are written untranslated, you could specify binary output by using the [ofstream](../standard-library/basic-ofstream-class.md#basic_ofstream) constructor `openmode` argument:
Input stream member functions are used for disk input. The member functions include:
9
+
Input stream member functions are used for disk input.
10
10
11
-
-[The open Function for Input Streams](#vclrftheopenfunctionforinputstreamsanchor11)
11
+
## <aname="vclrftheopenfunctionforinputstreamsanchor11"></a> open
12
12
13
-
-[The get](#vclrfthegetfunctionanchor12)
13
+
If you are using an input file stream (`ifstream`), you must associate that stream with a specific disk file. You can do this in the constructor, or you can use the `open` function. In either case, the arguments are the same.
14
14
15
-
-[The getline](#vclrfthegetlinefunctionanchor13)
16
-
17
-
-[The read](#vclrfthereadfunctionanchor14)
18
-
19
-
-[The seekg and tellg Functions](#vclrftheseekgandtellgfunctionsanchor7)
20
-
21
-
-[The close Function for Input Streams](#vclrftheclosefunctionforinputstreamsanchor15)
22
-
23
-
## <aname="vclrftheopenfunctionforinputstreamsanchor11"></a> The open Function for Input Streams
24
-
25
-
If you are using an input file stream (ifstream), you must associate that stream with a specific disk file. You can do this in the constructor, or you can use the `open` function. In either case, the arguments are the same.
26
-
27
-
You generally specify an [ios_base::openmode](../standard-library/ios-base-class.md#openmode) flag when you open the file associated with an input stream (the default mode is `ios::in`). For a list of the `open_mode` flags, see [The open](#vclrftheopenfunctionforinputstreamsanchor11). The flags can be combined with the bitwise OR ( | ) operator.
15
+
You generally specify an [ios_base::openmode](../standard-library/ios-base-class.md#openmode) flag when you open the file associated with an input stream (the default mode is `ios::in`). For a list of the `openmode` flags, see [ios_base::openmode](../standard-library/ios-base-class.md#openmode). The flags can be combined with the bitwise OR ( | ) operator.
28
16
29
17
To read a file, first use the `fail` member function to determine whether it exists:
30
18
@@ -35,7 +23,7 @@ if (ifile.fail())
35
23
// The file does not exist ...
36
24
```
37
25
38
-
## <a name="vclrfthegetfunctionanchor12"></a> The get
26
+
## <a name="vclrfthegetfunctionanchor12"></a> get
39
27
40
28
The unformatted `get` member function works like the `>>` operator with two exceptions. First, the `get` function includes white-space characters, whereas the extractor excludes white space when the `skipws` flag is set (the default). Second, the `get` function is less likely to cause a tied output stream (`cout`, for example) to be flushed.
41
29
@@ -70,7 +58,7 @@ int main()
70
58
1234
71
59
```
72
60
73
-
## <aname="vclrfthegetlinefunctionanchor13"></a> The getline
The `getline` member function is similar to the `get` function. Both functions allow a third argument that specifies the terminating character for input. The default value is the newline character. Both functions reserve one character for the required terminating character. However, `get` leaves the terminating character in the stream and `getline` removes the terminating character.
76
64
@@ -97,7 +85,7 @@ int main( )
97
85
test
98
86
```
99
87
100
-
## <aname="vclrfthereadfunctionanchor14"></a> The read
The `read` member function reads bytes from a file to a specified area of memory. The length argument determines the number of bytes read. If you do not include that argument, reading stops when the physical end of file is reached or, in the case of a text-mode file, when an embedded `EOF` character is read.
103
91
@@ -129,7 +117,7 @@ int main()
129
117
130
118
The program assumes that the data records are formatted exactly as specified by the structure with no terminating carriage return or line feed characters.
131
119
132
-
## <aname="vclrftheseekgandtellgfunctionsanchor7"></a> The seekg and tellg Functions
120
+
## <aname="vclrftheseekgandtellgfunctionsanchor7"></a> seekg and tellg
133
121
134
122
Input file streams keep an internal pointer to the position in the file where data is to be read next. You set this pointer with the `seekg` function, as shown here:
135
123
@@ -184,9 +172,9 @@ int main( )
184
172
}
185
173
```
186
174
187
-
## <aname="vclrftheclosefunctionforinputstreamsanchor15"></a> The close Function for Input Streams
175
+
## <aname="vclrftheclosefunctionforinputstreamsanchor15"></a> close
188
176
189
-
The `close` member function closes the disk file associated with an input file stream and frees the operating system file handle. The [ifstream](../standard-library/basic-ifstream-class.md) destructor closes the file for you, but you can use the `close` function if you need to open another file for the same stream object.
177
+
The `close` member function closes the disk file associated with an input file stream and frees the operating system file handle. The [`ifstream`](../standard-library/basic-ifstream-class.md) destructor closes the file for you, but you can use the `close` function if you need to open another file for the same stream object.
0 commit comments