-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_ostream.html
More file actions
447 lines (387 loc) · 18.7 KB
/
Copy pathbasic_ostream.html
File metadata and controls
447 lines (387 loc) · 18.7 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
<!doctype html>
<html class="cpprefjp" lang="ja" itemscope="" itemtype="http://schema.org/WebPage">
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-NXNBNVBTJS"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-NXNBNVBTJS');
</script>
<meta charset="UTF-8">
<title>std::basic_ostream - cpprefjp C++日本語リファレンス</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="keywords" content="
C++,標準ライブラリ,リファレンス,ドキュメント,STL,std,ostream,std,class template,ostream,wostream
">
<meta name="title" content="std::basic_ostream - cpprefjp C++日本語リファレンス" />
<meta itemprop="name" content="std::basic_ostream - cpprefjp C++日本語リファレンス" />
<meta property="og:title" content="std::basic_ostream - cpprefjp C++日本語リファレンス" />
<meta property="og:url" content="https://cpprefjp.github.io/reference/ostream/basic_ostream.html" />
<meta property="og:site_name" content="cpprefjp - C++日本語リファレンス" />
<meta property="og:type" content="article" />
<meta property="og:description" content="`basic_ostream` は、出力ストリームを表現するクラスである。" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="std::basic_ostream - cpprefjp C++日本語リファレンス" />
<meta name="twitter:url" content="https://cpprefjp.github.io/reference/ostream/basic_ostream.html" />
<meta name="twitter:description" content="`basic_ostream` は、出力ストリームを表現するクラスである。" />
<link rel="alternate" type="application/atom+xml" title="Atom" href="https://cpprefjp.github.io/rss.xml" />
<link rel="apple-touch-icon" sizes="180x180" href="../../static/favicons/apple-touch-icon.png?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722">
<link rel="icon" type="image/png" sizes="32x32" href="../../static/favicons/favicon-32x32.png?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722">
<link rel="icon" type="image/png" sizes="16x16" href="../../static/favicons/favicon-16x16.png?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722">
<link rel="manifest" href="../../manifest.json?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722">
<meta name="theme-color" content="#f5f8fc">
<link rel="stylesheet" href="../../static/pygments/default.css?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722">
<!-- <link rel="stylesheet" href="../../static/css/root.css"> -->
<link href="../../static/kunai/css/kunai-stage-0.css?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722" rel="stylesheet">
<link href="../../static/kunai/css/kunai-stage-1.css?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722" rel="stylesheet">
<link href="../../static/kunai/css/kunai-stage-2.css?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722" rel="stylesheet">
<link href="../../static/kunai/css/kunai-stage-3.css?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722" rel="stylesheet">
<script type="text/javascript" src="../../static/kunai/js/kunai-vendor.js?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722"></script>
<script type="text/javascript" src="../../static/kunai/js/kunai.js?cachebust=b2142794d8ca9924d883222f0df04f8c964ce722"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var kn = new Kunai;
kn.cpprefjp();
});
</script>
</head>
<body>
<header data-kunai-mdinfo="{"meta": {"header": ["ostream"], "namespace": ["std"], "id-type": ["class template"], "alias": ["ostream,wostream"]}, "sources": [], "page_id": ["reference", "ostream", "basic_ostream"]}">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../../index.html">
<div class="title-wrapper clearfix">
<div class="title">cpprefjp - C++日本語リファレンス</div>
</div>
</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>
<div class="google-search">
<script>
(function() {
var cx = '013316413321391058734:ji_u66hl7hq';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<div class="gcse-search"></div>
</div>
</li>
<li>
<a href="https://github.com/cpprefjp/site">GitHub Project</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<main id="main" role="main">
<div class="container-fluid">
<div class="row">
<div class="col-sm-9 col-sm-push-3" itemscope itemtype="http://schema.org/Article">
<div class="row">
<div class="col-sm-12 google-search-result">
<gcse:searchresults></gcse:searchresults>
</div>
</div>
<div class="row">
<div class="col-sm-12 content-header">
<ol class="breadcrumb">
<li itemscope itemtype="http://www.schema.org/SiteNavigationElement">
<span>
<a href="../../index.html" itemprop="url">
<i class="fa fa-fw fa-home"></i>
</a>
</span>
</li>
<li itemscope itemtype="http://www.schema.org/SiteNavigationElement">
<span>
<a href="../../reference.html" itemprop="url">
<span itemprop="name">リファレンス</span>
</a>
</span>
</li>
<li itemscope itemtype="http://www.schema.org/SiteNavigationElement">
<span>
<a href="../../reference/ostream.html" itemprop="url">
<span itemprop="name">ostream</span>
</a>
</span>
</li>
<li class="active" itemscope itemtype="http://www.schema.org/SiteNavigationElement">
<span>
<span itemprop="name">basic_ostream</span>
</span>
</li>
</ol>
<div class="crsearch"></div>
</div>
</div>
<div class="row">
<div class="col-sm-12 edit-button">
<p class="text-right"><small>
最終更新日時(UTC):
<span itemprop="datePublished" content="2026-04-25T00:09:04">
2026年04月25日 00時09分04秒
</span>
<br/>
<span itemprop="author" itemscope itemtype="http://schema.org/Person">
<span itemprop="name">rotarymars</span>
</span>
が更新
</small></p>
<p class="text-right">
<a class="history" target="_blank" href="https://github.com/cpprefjp/site/commits/master/reference/ostream/basic_ostream.md">
<span class="fa fa-fw fa-clock-o fa-flip-horizontal"></span>履歴
</a>
<a class="edit" target="_blank" href="https://github.com/cpprefjp/site/edit/master/reference/ostream/basic_ostream.md">
<span class="fa fa-fw fa-pencil"></span>編集
</a>
</p>
</div>
</div>
<div class="row">
<div class="col-sm-12 content-body">
<div class="identifier-type">class template</div><div class="header"><ostream></div><h1 itemprop="name"><span class="namespace" title="namespace std">std::</span><span class="token">basic_ostream</span></h1>
<div itemprop="articleBody"><p><div class="codehilite"><pre><span></span><code><span class="k">namespace</span><span class="w"> </span><span class="nn">std</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">template</span><span class="o"><</span><span class="k">class</span><span class="w"> </span><span class="nc">CharT</span><span class="p">,</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">Traits</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n"><a href="../string/char_traits.html">char_traits</a></span><span class="o"><</span><span class="n">CharT</span><span class="o">>></span>
<span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">basic_ostream</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="k">virtual</span><span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n"><a href="../ios/basic_ios.html">basic_ios</a></span><span class="o"><</span><span class="n">CharT</span><span class="p">,</span><span class="w"> </span><span class="n">Traits</span><span class="o">></span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="err">……</span><span class="w"> </span><span class="p">};</span>
<span class="w"> </span><span class="k">using</span><span class="w"> </span><span class="n">ostream</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">basic_ostream</span><span class="o"><</span><span class="kt">char</span><span class="o">></span><span class="p">;</span>
<span class="w"> </span><span class="k">using</span><span class="w"> </span><span class="n">wostream</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">basic_ostream</span><span class="o"><</span><span class="kt">wchar_t</span><span class="o">></span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
</p>
<h2>概要</h2>
<p><code>basic_ostream</code> は、出力ストリームを表現するクラスである。
すなわち、<code><a href="../ios/basic_ios/rdbuf.html">rdbuf()</a></code> が指し示すストリームバッファオブジェクトに対する書き込み操作を提供する。</p>
<p>各種の出力関数——特に<code><<</code>演算子——がクラスのメンバ関数・非メンバ関数として定義されている。
このため、ユーザーコードで入力処理を実装する際には、<code>basic_ostream</code>、あるいはそれに対する別名である<code>ostream</code>や<code>wostream</code>などの型への参照を実引数として受け取るようにすると良い。</p>
<p>テンプレートパラメータとして文字型を受け取るようになっており、使用を容易にするため、以下のパラメータ設定済みエイリアスが定義されている。
このエイリアスは<code><ostream></code>ヘッダと<code><iosfwd></code>ヘッダで定義されている。</p>
<table border="1" bordercolor="#888" style="border-collapse:collapse">
<thead>
<tr>
<th>エイリアス</th>
<th>説明</th>
<th>対応バージョン</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>ostream</code></td>
<td><code>char</code>型。ASCII、UTF-8等のマルチバイト文字列や、バイナリデータとして使用する。</td>
<td></td>
</tr>
<tr>
<td><code>wostream</code></td>
<td><code>wchar_t</code>型。ワイド文字列として使用する。</td>
<td></td>
</tr>
</tbody>
</table>
<h2>書式化出力関数と非書式化出力関数</h2>
<p><code>basic_ostream</code>での出力操作は、書式化出力関数と非書式化出力関数の2種類に分類される。</p>
<h3>書式化出力関数と非書式化出力関数の効果</h3>
<p>注意:書式化出力関数と非書式化出力関数すべてについて、「効果」の項目は以下の処理を前提として記載している。</p>
<p>書式化出力関数・非書式化出力関数は、出力処理に先立って<code>sentry</code>オブジェクトを構築し、関数から脱出する前に破棄する。
構築した <code><a href="basic_ostream/sentry.html">sentry</a></code> オブジェクトが <code><a href="basic_ostream/sentry/op_bool.html">operator bool</a></code> 関数で <code>true</code> に変換できる場合のみ、実際の出力処理(各関数の「効果」として記載した処理)が実行される。</p>
<p>(書式化出力関数のみ)<code><a href="basic_ostream/sentry/op_bool.html">operator bool</a></code> 関数の結果が <code>false</code> であったら、<code><a href="../ios/basic_ios/setstate.html">setstate</a>(ios_base::badbit)</code> を呼び出す。</p>
<p>関数内部で<a class="cpprefjp-defined-word" data-desc="問題が発生したときに、現在実行位置を過去に通過・記録した位置に戻し、文脈情報を添えて紐づけられた処理(例外ハンドラー)を呼び出す仕組み。またはその事態">例外</a>が送出された場合、<code>ios_base::badbit</code> を設定する。
そして、<code>(<a href="../ios/basic_ios/exceptions.html">exceptions</a>() & <a href="../ios/ios_base/type-iostate.html">badbit</a>) != 0</code> であれば<a class="cpprefjp-defined-word" data-desc="問題が発生したときに、現在実行位置を過去に通過・記録した位置に戻し、文脈情報を添えて紐づけられた処理(例外ハンドラー)を呼び出す仕組み。またはその事態">例外</a>を再送出する。</p>
<h2>メンバ</h2>
<p>基底クラスである <code><a href="../ios/ios_base.html">ios_base</a></code> と<code><a href="../ios/basic_ios.html">basic_ios</a></code> も参照のこと。</p>
<h3>型</h3>
<table border="1" bordercolor="#888" style="border-collapse:collapse">
<thead>
<tr>
<th>名前</th>
<th>説明</th>
<th>対応バージョン</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="basic_ostream/sentry.html">sentry</a></code></td>
<td>出力操作の前処理・後処理</td>
<td></td>
</tr>
</tbody>
</table>
<h3>構築・破棄</h3>
<table border="1" bordercolor="#888" style="border-collapse:collapse">
<thead>
<tr>
<th>名前</th>
<th>説明</th>
<th>対応バージョン</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="basic_ostream/op_constructor.html">(constructor)</a></code></td>
<td>コンストラクタ</td>
<td></td>
</tr>
<tr>
<td><code><a href="basic_ostream/op_destructor.html">(destructor)</a></code></td>
<td>デストラクタ</td>
<td></td>
</tr>
</tbody>
</table>
<ul>
<li>コピーコンストラクタとコピー代入演算子はdelete定義されている。</li>
<li>ムーブコンストラクタ・ムーブ代入演算子と<code>swap</code>はprotectedで定義されている。</li>
</ul>
<h3>出力処理</h3>
<table border="1" bordercolor="#888" style="border-collapse:collapse">
<thead>
<tr>
<th>名前</th>
<th>説明</th>
<th>対応バージョン</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="basic_ostream/op_ostream.html">operator<<</a></code></td>
<td>書式化出力・マニピュレータの実行</td>
<td></td>
</tr>
<tr>
<td><code><a href="basic_ostream/put.html">put</a></code></td>
<td>文字の出力</td>
<td></td>
</tr>
<tr>
<td><code><a href="basic_ostream/write.html">write</a></code></td>
<td>文字列・バイト列の出力</td>
<td></td>
</tr>
<tr>
<td><code><a href="basic_ostream/flush.html">flush</a></code></td>
<td>ストリームバッファのフラッシュ</td>
<td></td>
</tr>
</tbody>
</table>
<p><code><<</code>演算子のほとんどは書式化出力関数である。
その他のメンバ関数は非書式化出力関数である。</p>
<h3>シーク</h3>
<table border="1" bordercolor="#888" style="border-collapse:collapse">
<thead>
<tr>
<th>名前</th>
<th>説明</th>
<th>対応バージョン</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="basic_ostream/tellp.html">tellp</a></code></td>
<td>現在の読み取り位置を取得する</td>
<td></td>
</tr>
<tr>
<td><code><a href="basic_ostream/seekp.html">seekp</a></code></td>
<td>読み取り位置を移動する</td>
<td></td>
</tr>
</tbody>
</table>
<h3>protectedメンバ関数</h3>
<table border="1" bordercolor="#888" style="border-collapse:collapse">
<thead>
<tr>
<th>名前</th>
<th>説明</th>
<th>対応バージョン</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="basic_ostream/op_constructor.html">(constructor)</a></code></td>
<td>コンストラクタ</td>
<td></td>
</tr>
<tr>
<td><code><a href="basic_ostream/op_assign.html">operator=</a></code></td>
<td>代入</td>
<td>C++11</td>
</tr>
<tr>
<td><code><a href="basic_ostream/swap.html">swap</a></code></td>
<td>値の交換</td>
<td>C++11</td>
</tr>
</tbody>
</table>
<h2>非メンバ関数</h2>
<table border="1" bordercolor="#888" style="border-collapse:collapse">
<thead>
<tr>
<th>名前</th>
<th>説明</th>
<th>対応バージョン</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="basic_ostream/op_ostream_free.html">operator<<</a></code></td>
<td>文字・文字列の書式化出力、および、右辺値ストリームへの出力</td>
<td></td>
</tr>
</tbody>
</table>
<h2>参照</h2>
<ul>
<li>基底クラス<ul>
<li><code><a href="../ios/ios_base.html">ios_base</a></code></li>
<li><code><a href="../ios/basic_ios.html">basic_ios</a></code></li>
</ul>
</li>
<li><code>basic_ostream<></code>型のオブジェクト<ul>
<li><code><a href="../iostream/cout.html">cout</a></code></li>
<li><code><a href="../iostream/wcout.html">wcout</a></code></li>
<li><code><a href="../iostream/clog.html">clog</a></code></li>
<li><code><span href="https://cpprefjp.github.io/reference/iostream/wclog.md.nolink">wclog</span></code></li>
<li><code><a href="../iostream/cerr.html">cerr</a></code></li>
<li><code><span href="https://cpprefjp.github.io/reference/iostream/wcerr.md.nolink">wcerr</span></code></li>
</ul>
</li>
</ul></div>
</div>
</div>
</div>
<div id="sidebar" class="col-sm-3 col-sm-pull-9">
</div>
</div>
</div>
</main>
<footer class="footer navbar navbar-default">
<div class="container-fluid">
<p><small>
本サイトの情報は、
<a href="https://creativecommons.org/licenses/by/4.0/deed.ja" rel="nofollow">クリエイティブ・コモンズ 表示 4.0 非移植 ライセンス(CC BY)</a>
の下に提供されています。
</small></p>
</div>
</footer>
</body>
</html>