-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio_flags.html
More file actions
621 lines (410 loc) · 11.4 KB
/
io_flags.html
File metadata and controls
621 lines (410 loc) · 11.4 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!-- Mirrored from cppreference.com/io_flags.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:32 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">
<title>I/O Flags</title>
<link href="cppreference.css" rel="stylesheet" type="text/css">
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
</head>
<body onload="prettyPrint()">
<table>
<tr>
<td>
<div class="body-content">
<div class="header-box">
<a href="index-2.html">cppreference.com</a> > I/O Flags
</div>
<h1>C++ I/O Flags</h1>
<a name="format_flags">
<h2>Format flags</h2>
</a>
<p>C++ defines some format flags for standard input and output, which
can be manipulated with the <a href="cppio/flags.html">flags()</a>,
<a href="cppio/setf.html">setf()</a>, and <a href=
"cppio/unsetf.html">unsetf()</a> functions. For example,</p>
<pre>
cout.setf(ios::left);
</pre>
<p>turns on left justification for all output directed to
<strong>cout</strong>.</p>
<table class="misc-table">
<tr class="misc-table-tr-1">
<th>Flag</th>
<th>Meaning</th>
</tr>
<tr class="misc-table-tr-2">
<td>boolalpha</td>
<td>Boolean values can be input/output using the words
"true" and "false".</td>
</tr>
<tr class="misc-table-tr-1">
<td>dec</td>
<td>Numeric values are displayed in decimal.</td>
</tr>
<tr class="misc-table-tr-2">
<td>fixed</td>
<td>Display floating point values using normal notation (as
opposed to scientific).</td>
</tr>
<tr class="misc-table-tr-1">
<td>hex</td>
<td>Numeric values are displayed in hexidecimal.</td>
</tr>
<tr class="misc-table-tr-2">
<td>internal</td>
<td>If a numeric value is padded to fill a field, spaces are
inserted between the sign and base character.</td>
</tr>
<tr class="misc-table-tr-1">
<td>left</td>
<td>Output is left justified.</td>
</tr>
<tr class="misc-table-tr-2">
<td>oct</td>
<td>Numeric values are displayed in octal.</td>
</tr>
<tr class="misc-table-tr-1">
<td>right</td>
<td>Output is right justified.</td>
</tr>
<tr class="misc-table-tr-2">
<td>scientific</td>
<td>Display floating point values using scientific notation.</td>
</tr>
<tr class="misc-table-tr-1">
<td>showbase</td>
<td>Display the base of all numeric values.</td>
</tr>
<tr class="misc-table-tr-2">
<td>showpoint</td>
<td>Display a decimal and extra zeros, even when not needed.</td>
</tr>
<tr class="misc-table-tr-1">
<td>showpos</td>
<td>Display a leading plus sign before positive numeric
values.</td>
</tr>
<tr class="misc-table-tr-2">
<td>skipws</td>
<td>Discard whitespace characters (spaces, tabs, newlines) when
reading from a stream.</td>
</tr>
<tr class="misc-table-tr-1">
<td>unitbuf</td>
<td>Flush the buffer after each insertion.</td>
</tr>
<tr class="misc-table-tr-2">
<td>uppercase</td>
<td>Display the "e" of scientific notation and the
"x" of hexidecimal notation as capital letters.</td>
</tr>
</table>
<a name="manipulators">
<h2>Manipulators</h2>
</a>
<p>You can also manipulate flags indirectly, using the following
<i>manipulators</i>. Most programmers are familiar with the
<strong>endl</strong> manipulator, which might give you an idea of
how manipulators are used. For example, to set the <i>dec</i> flag,
you might use the following command:</p>
<pre>
cout << dec;
</pre>
<table class="misc-table">
<tr class="misc-table-tr-1">
<th colspan="4">Manipulators defined in <iostream></th>
</tr>
<tr class="misc-table-tr-1">
<th>Manipulator</th>
<th>Description</th>
<th>Input</th>
<th>Output</th>
</tr>
<tr class="misc-table-tr-2">
<td>boolalpha</td>
<td>Turns on the boolalpha flag</td>
<td>X</td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>dec</td>
<td>Turns on the dec flag</td>
<td>X</td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>endl</td>
<td>Output a newline character, flush the stream</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>ends</td>
<td>Output a null character</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>fixed</td>
<td>Turns on the fixed flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>flush</td>
<td>Flushes the stream</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>hex</td>
<td>Turns on the hex flag</td>
<td>X</td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>internal</td>
<td>Turns on the internal flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>left</td>
<td>Turns on the left flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>noboolalpha</td>
<td>Turns off the boolalpha flag</td>
<td>X</td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>noshowbase</td>
<td>Turns off the showbase flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>noshowpoint</td>
<td>Turns off the showpoint flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>noshowpos</td>
<td>Turns off the showpos flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>noskipws</td>
<td>Turns off the skipws flag</td>
<td>X</td>
<td></td>
</tr>
<tr class="misc-table-tr-2">
<td>nounitbuf</td>
<td>Turns off the unitbuf flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>nouppercase</td>
<td>Turns off the uppercase flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>oct</td>
<td>Turns on the oct flag</td>
<td>X</td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>right</td>
<td>Turns on the right flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>scientific</td>
<td>Turns on the scientific flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>showbase</td>
<td>Turns on the showbase flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>showpoint</td>
<td>Turns on the showpoint flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>showpos</td>
<td>Turns on the showpos flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>skipws</td>
<td>Turns on the skipws flag</td>
<td>X</td>
<td></td>
</tr>
<tr class="misc-table-tr-1">
<td>unitbuf</td>
<td>Turns on the unitbuf flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>uppercase</td>
<td>Turns on the uppercase flag</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>ws</td>
<td>Skip any leading whitespace</td>
<td>X</td>
<td></td>
</tr>
</table>
<table class="misc-table">
<tr class="misc-table-tr-1">
<th colspan="4">Manipulators defined in <iomanip></th>
</tr>
<tr class="misc-table-tr-1">
<th>Manipulator</th>
<th>Description</th>
<th>Input</th>
<th>Output</th>
</tr>
<tr class="misc-table-tr-2">
<td>resetiosflags( long f )</td>
<td>Turn off the flags specified by <i>f</i></td>
<td>X</td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>setbase( int base )</td>
<td>Sets the number base to <i>base</i></td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>setfill( int ch )</td>
<td>Sets the fill character to <i>ch</i></td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>setiosflags( long f )</td>
<td>Turn on the flags specified by <i>f</i></td>
<td>X</td>
<td>X</td>
</tr>
<tr class="misc-table-tr-2">
<td>setprecision( int p )</td>
<td>Sets the number of digits of precision</td>
<td></td>
<td>X</td>
</tr>
<tr class="misc-table-tr-1">
<td>setw( int w )</td>
<td>Sets the field width to <i>w</i></td>
<td></td>
<td>X</td>
</tr>
</table>
<a name="state_flags">
<h2>State flags</h2>
</a>
<p>The I/O stream state flags tell you the current state of an I/O
stream. The flags are:</p>
<table class="misc-table">
<tbody>
<tr class="misc-table-tr-1">
<th>Flag</th>
<th>Meaning</th>
</tr>
<tr class="misc-table-tr-2">
<td>badbit</td>
<td>a fatal error has occurred</td>
</tr>
<tr class="misc-table-tr-1">
<td>eofbit</td>
<td>EOF has been found</td>
</tr>
<tr class="misc-table-tr-2">
<td>failbit</td>
<td>a nonfatal error has occurred</td>
</tr>
<tr class="misc-table-tr-1">
<td>goodbit</td>
<td>no errors have occurred</td>
</tr>
</tbody>
</table>
<a name="mode_flags">
<h2>Mode flags</h2>
</a>
<p>The I/O stream mode flags allow you to access files in different
ways. The flags are:</p>
<table class="misc-table">
<tbody>
<tr class="misc-table-tr-1">
<th>Mode</th>
<th>Meaning</th>
</tr>
<tr class="misc-table-tr-2">
<td>ios::app</td>
<td>append output</td>
</tr>
<tr class="misc-table-tr-1">
<td>ios::ate</td>
<td>seek to EOF when opened</td>
</tr>
<tr class="misc-table-tr-2">
<td>ios::binary</td>
<td>open the file in binary mode</td>
</tr>
<tr class="misc-table-tr-1">
<td>ios::in</td>
<td>open the file for reading</td>
</tr>
<tr class="misc-table-tr-2">
<td>ios::out</td>
<td>open the file for writing</td>
</tr>
<tr class="misc-table-tr-1">
<td>ios::trunc</td>
<td>overwrite the existing file</td>
</tr>
</tbody>
</table>
</div>
</td>
<script src="../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/io_flags.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:24:32 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>