<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" dir="ltr" class="client-nojs">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Input/output library - cppreference.com</title>
<meta charset="UTF-8">
<meta name="generator" content="MediaWiki 1.18.2">
<link rel="shortcut icon" href="../../favicon.ico">
<link rel="stylesheet" href="../../common/load202e.css?debug=false&amp;lang=en&amp;modules=mediawiki.legacy.commonPrint%2Cshared%7Cskins.cppreference2&amp;only=styles&amp;skin=cppreference2&amp;*">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="../../common/load7fe1.css?debug=false&amp;lang=en&amp;modules=site&amp;only=styles&amp;skin=cppreference2&amp;*">
<style>a:lang(ar),a:lang(ckb),a:lang(fa),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}a.new,#quickbar a.new{color:#ba0000}#toc{display:none}.editsection{display:none}

/* cache key: mwiki1-mwiki_en_:resourceloader:filter:minify-css:4:b677bc2b5ec37947892a2d0853532528 */</style>
<script src="../../common/load404e.php?debug=false&amp;lang=en&amp;modules=startup&amp;only=scripts&amp;skin=cppreference2&amp;*"></script><script>if(window.mw){
	mw.config.set({"wgCanonicalNamespace": "", "wgCanonicalSpecialPageName": false, "wgNamespaceNumber": 0, "wgPageName": "cpp/io", "wgTitle": "cpp/io", "wgCurRevisionId": 33661, "wgArticleId": 476, "wgIsArticle": true, "wgAction": "view", "wgUserName": null, "wgUserGroups": ["*"], "wgCategories": [], "wgBreakFrames": false, "wgRestrictionEdit": [], "wgRestrictionMove": []});
}
</script><script>if(window.mw){
	mw.loader.load(["mediawiki.page.startup"]);
}
</script><style type="text/css">/*<![CDATA[*/
.source-cpp {line-height: normal;}
.source-cpp li, .source-cpp pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for cpp
 * CSS class: source-cpp, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.cpp.source-cpp .de1, .cpp.source-cpp .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.cpp.source-cpp  {font-family:monospace;}
.cpp.source-cpp .imp {font-weight: bold; color: red;}
.cpp.source-cpp li, .cpp.source-cpp .li1 {font-weight: normal; vertical-align:top;}
.cpp.source-cpp .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.cpp.source-cpp .li2 {font-weight: bold; vertical-align:top;}
.cpp.source-cpp .kw1 {color: #0000dd;}
.cpp.source-cpp .kw2 {color: #0000ff;}
.cpp.source-cpp .kw3 {color: #0000dd;}
.cpp.source-cpp .kw4 {color: #0000ff;}
.cpp.source-cpp .co1 {color: #909090;}
.cpp.source-cpp .co2 {color: #339900;}
.cpp.source-cpp .coMULTI {color: #ff0000; font-style: italic;}
.cpp.source-cpp .es0 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es1 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es2 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es3 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es4 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es5 {color: #008000; font-weight: bold;}
.cpp.source-cpp .br0 {color: #008000;}
.cpp.source-cpp .sy0 {color: #008000;}
.cpp.source-cpp .sy1 {color: #000080;}
.cpp.source-cpp .sy2 {color: #000040;}
.cpp.source-cpp .sy3 {color: #000040;}
.cpp.source-cpp .sy4 {color: #008080;}
.cpp.source-cpp .st0 {color: #008000;}
.cpp.source-cpp .nu0 {color: #000080;}
.cpp.source-cpp .nu6 {color: #000080;}
.cpp.source-cpp .nu8 {color: #000080;}
.cpp.source-cpp .nu12 {color: #000080;}
.cpp.source-cpp .nu16 {color:#000080;}
.cpp.source-cpp .nu17 {color:#000080;}
.cpp.source-cpp .nu18 {color:#000080;}
.cpp.source-cpp .nu19 {color:#000080;}
.cpp.source-cpp .ln-xtra, .cpp.source-cpp li.ln-xtra, .cpp.source-cpp div.ln-xtra {background-color: #ffc;}
.cpp.source-cpp span.xtra { display:block; }

/*]]>*/
</style>
<!--[if lt IE 7]><style type="text/css">body{behavior:url("/mwiki/skins/cppreference2/csshover.min.htc")}</style><![endif]-->
</head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_io action-view skin-cppreference2 cpp-navbar">
        <!-- header -->
        
        <!-- /header -->
        <!-- content -->
        <div id="cpp-content-base">
            <div id="content">
                <a id="top"></a>
                <div id="mw-js-message" style="display:none;"></div>
                                <!-- firstHeading -->
                <h1 id="firstHeading" class="firstHeading">Input/output library</h1>
                <!-- /firstHeading -->
                <!-- bodyContent -->
                <div id="bodyContent">
                                        <!-- tagline -->
                    <div id="siteSub">From cppreference.com</div>
                    <!-- /tagline -->
                                        <!-- subtitle -->
                    <div id="contentSub"><span class="subpages">&lt; <a href="../cpp.html" title="cpp">cpp</a></span></div>
                    <!-- /subtitle -->
                                                            <!-- bodycontent -->
                    <div lang="en" dir="ltr" class="mw-content-ltr">
<div class="t-navbar" style="">
<div class="t-navbar-sep"> </div>
<div class="t-navbar-head">
<a href="../cpp.html" title="cpp"> C++</a><div class="t-navbar-menu"><div><div>
<table class="t-sb-list-begin" cellpadding="0" style="line-height:1.1em;">
<tr><td colspan="5">  <a href="language.html" title="cpp/language"> Language</a>
</td></tr>
<tr><td colspan="5">  <a href="concept.html" title="cpp/concept"> Concepts</a>
</td></tr>
<tr><td colspan="5">  <a href="utility.html" title="cpp/utility"> Utilities library</a>
</td></tr>
<tr><td colspan="5">  <a href="string.html" title="cpp/string"> Strings library</a>
</td></tr>
<tr><td colspan="5">  <a href="container.html" title="cpp/container"> Containers library</a>
</td></tr>
<tr><td colspan="5">  <a href="algorithm.html" title="cpp/algorithm"> Algorithms library</a>
</td></tr>
<tr><td colspan="5">  <a href="iteratorhtml.html" title="cpp/iterator"> Iterators library</a>
</td></tr>
<tr><td colspan="5">  <a href="numeric.html" title="cpp/numeric"> Numerics library</a>
</td></tr>
<tr><td colspan="5">  <strong class="selflink"> Input/output library</strong>
</td></tr>
<tr><td colspan="5">  <a href="locale.html" title="cpp/locale"> Localizations library</a>
</td></tr>
<tr><td colspan="5">  <a href="regex.html" title="cpp/regex"> Regular expressions library</a> <span class="t-mark">(C++11)</span>
</td></tr>
<tr><td colspan="5">  <a href="atomic.html" title="cpp/atomic"> Atomic operations library</a> <span class="t-mark">(C++11)</span>
</td></tr>
<tr><td colspan="5">  <a href="thread.html" title="cpp/thread"> Thread support library</a> <span class="t-mark">(C++11)</span>
</td></tr>
</table>
</div></div></div>
</div>
<div class="t-navbar-sep"> </div>
<div class="t-navbar-head">
<strong class="selflink"> Input/output library</strong><div class="t-navbar-menu"><div><div>
<table class="t-sb-list-begin" cellpadding="0" style="">
<tr><td colspan="5">  <a href="io/manip.html" title="cpp/io/manip"> I/O manipulators</a>
</td></tr>
<tr><td colspan="5">  <a href="io/c.html" title="cpp/io/c"> C-style I/O</a>
</td></tr>
<tr class="t-sb-list-h1"><td colspan="5">  Buffers
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_streambuf.html" title="cpp/io/basic streambuf">basic_streambuf</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_filebuf.html" title="cpp/io/basic filebuf">basic_filebuf</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_stringbuf.html" title="cpp/io/basic stringbuf">basic_stringbuf</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr>
<td><a href="io/strstreambuf.html" title="cpp/io/strstreambuf">strstreambuf</a></td>
<td><span class="t-mark">(deprecated)</span></td>
</tr></table>
</td></tr>
<tr class="t-sb-list-h1"><td colspan="5">  Streams
</td></tr>
<tr class="t-sb-list-h2"><td colspan="5">  Abstractions
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/ios_base.html" title="cpp/io/ios base">ios_base</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_ios.html" title="cpp/io/basic ios">basic_ios</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_istream.html" title="cpp/io/basic istream">basic_istream</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_ostream.html" title="cpp/io/basic ostream">basic_ostream</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_iostream.html" title="cpp/io/basic iostream">basic_iostream</a></td></tr></table>
</td></tr>
<tr class="t-sb-list-h2"><td colspan="5">  File I/O
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_ifstream.html" title="cpp/io/basic ifstream">basic_ifstream</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_ofstream.html" title="cpp/io/basic ofstream">basic_ofstream</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_fstreamhtml.html" title="cpp/io/basic fstream">basic_fstream</a></td></tr></table>
</td></tr>
<tr class="t-sb-list-h2"><td colspan="5">  String I/O
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_istringstream.html" title="cpp/io/basic istringstream">basic_istringstream</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_ostringstream.html" title="cpp/io/basic ostringstream">basic_ostringstream</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/basic_stringstream.html" title="cpp/io/basic stringstream">basic_stringstream</a></td></tr></table>
</td></tr>
<tr class="t-sb-list-h2"><td colspan="5">  Array I/O
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr>
<td><a href="io/istrstreamhtml.html" title="cpp/io/istrstream">istrstream</a></td>
<td><span class="t-mark">(deprecated)</span></td>
</tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr>
<td><a href="io/ostrstream.html" title="cpp/io/ostrstream">ostrstream</a></td>
<td><span class="t-mark">(deprecated)</span></td>
</tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr>
<td><a href="io/strstream.html" title="cpp/io/strstream">strstream</a></td>
<td><span class="t-mark">(deprecated)</span></td>
</tr></table>
</td></tr>
<tr class="t-sb-list-h1"><td colspan="5">  Types
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/streamoffhtml.html" title="cpp/io/streamoff">streamoff</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/streamsize.html" title="cpp/io/streamsize">streamsize</a></td></tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr><td><a href="io/fpos.html" title="cpp/io/fpos">fpos</a></td></tr></table>
</td></tr>
<tr class="t-sb-list-h1"><td colspan="5">  Error category interface
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr>
<td><a href="io/iostream_categoryhtml.html" title="cpp/io/iostream category">iostream_category</a></td>
<td><span class="t-mark">(C++11)</span></td>
</tr></table>
</td></tr>
<tr><td colspan="5"> <table class="t-sb-list-ln-table"><tr>
<td><a href="io/io_errc.html" title="cpp/io/io errc">io_errc</a></td>
<td><span class="t-mark">(C++11)</span></td>
</tr></table>
</td></tr>
</table>
</div></div></div>
</div>
<div class="t-navbar-sep"> </div>
</div>
<p>C++ includes two input/output libraries: a modern, stream-based I/O library and the standard set of C-style I/O functions.
</p>
<table id="toc" class="toc"><tr><td>
<div id="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1 tocsection-1">
<a href="#Stream-based_I.2FO"><span class="tocnumber">1</span> <span class="toctext">Stream-based I/O</span></a>
<ul>
<li class="toclevel-2"><a href="#Abstraction"><span class="tocnumber">1.1</span> <span class="toctext">Abstraction</span></a></li>
<li class="toclevel-2"><a href="#File_I.2F0_implementation"><span class="tocnumber">1.2</span> <span class="toctext">File I/0 implementation</span></a></li>
<li class="toclevel-2"><a href="#String_I.2F0_implementation"><span class="tocnumber">1.3</span> <span class="toctext">String I/0 implementation</span></a></li>
<li class="toclevel-2"><a href="#Array_I.2FO_implementations"><span class="tocnumber">1.4</span> <span class="toctext">Array I/O implementations</span></a></li>
<li class="toclevel-2 tocsection-2"><a href="#Typedefs"><span class="tocnumber">1.5</span> <span class="toctext">Typedefs</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#I.2FO_Manipulators"><span class="tocnumber">1.6</span> <span class="toctext">I/O Manipulators</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#Types"><span class="tocnumber">1.7</span> <span class="toctext">Types</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#Error_category_interface"><span class="tocnumber">1.8</span> <span class="toctext">Error category interface</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-6"><a href="#C-style_IO"><span class="tocnumber">2</span> <span class="toctext">C-style IO</span></a></li>
</ul>
</td></tr></table>
<h3>
<span class="editsection">[<a href="http://en.cppreference.com/mwiki/index.php?title=cpp/io&amp;action=edit&amp;section=1" title="Edit section: Stream-based I/O">edit</a>]</span> <span class="mw-headline" id="Stream-based_I.2FO">Stream-based I/O</span>
</h3>
<p>The stream-based input/output library is organized around abstract input/output devices. These abstract devices allow the same code to handle input/output to files, memory streams, or custom adaptor devices that perform arbitrary operations (e.g. compression) on the fly.
</p>
<p>Most of the classes are templated, so they can be adapted to any basic character type. Separate typedefs are provided for the most common basic character types (<span class="mw-geshi cpp source-cpp"><span class="kw4">char</span></span> and <span class="mw-geshi cpp source-cpp"><span class="kw4">wchar_t</span></span>).  The classes are organized into the following hierarchy:
</p>
<div class="t-inheritance-diagram">
<div class="center"><div style="height: 392px; width: 531px; ">
<map name="ImageMap_1_684885220"><area href="io/ios_base.html" shape="rect" coords="215,4,318,36" alt="cpp/io/ios base" title="cpp/io/ios base">
<area href="io/basic_ios.html" shape="rect" coords="206,69,327,107" alt="cpp/io/basic ios" title="cpp/io/basic ios">
<area href="io/basic_istream.html" shape="rect" coords="292,139,413,177" alt="cpp/io/basic istream" title="cpp/io/basic istream">
<area href="io/basic_ostream.html" shape="rect" coords="120,139,241,177" alt="cpp/io/basic ostream" title="cpp/io/basic ostream">
<area href="io/basic_ifstream.html" shape="rect" coords="395,280,515,318" alt="cpp/io/basic ifstream" title="cpp/io/basic ifstream">
<area href="io/basic_istringstream.html" shape="rect" coords="383,350,527,388" alt="cpp/io/basic istringstream" title="cpp/io/basic istringstream">
<area href="io/basic_iostream.html" shape="rect" coords="206,209,327,247" alt="cpp/io/basic iostream" title="cpp/io/basic iostream">
<area href="io/basic_ofstream.html" shape="rect" coords="17,280,138,318" alt="cpp/io/basic ofstream" title="cpp/io/basic ofstream">
<area href="io/basic_ostringstream.html" shape="rect" coords="4,350,152,388" alt="cpp/io/basic ostringstream" title="cpp/io/basic ostringstream">
<area href="io/basic_fstreamhtml.html" shape="rect" coords="189,280,310,318" alt="cpp/io/basic fstream" title="cpp/io/basic fstream">
<area href="io/basic_stringstream.html" shape="rect" coords="179,350,320,388" alt="cpp/io/basic stringstream" title="cpp/io/basic stringstream"></map><img alt="std-io-complete-inheritance.svg" src="../../common/images/0/06/std-io-complete-inheritance.svg" width="531" height="392" usemap="#ImageMap_1_684885220"><div style="margin-left: 511px; margin-top: -20px; text-align: left;"><a href="http://en.cppreference.com/w/File:std-io-complete-inheritance.svg" title="About this image"><img alt="About this image" src="../../common/extensions/ImageMap/desc-20.png" style="border: none;"></a></div>
</div></div>
<div style="text-align:center;">
<p><span style="font-size:0.7em; line-height:130%">Inheritance diagram</span>
</p>
</div>
</div>
<table class="t-dcl-list-begin">
<tr><td colspan="2"> <h5> <span class="mw-headline" id="Abstraction">  Abstraction </span>
</h5>
</td></tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/ios_base.html" title="cpp/io/ios base"> ios_base</a></div></div>
</td>
<td>   manages formatting flags and input/output exceptions <br><span class="t-mark">(class)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_ios.html" title="cpp/io/basic ios"> basic_ios</a></div></div>
</td>
<td>   manages an arbitrary stream buffer <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_streambuf.html" title="cpp/io/basic streambuf"> basic_streambuf</a></div></div>
</td>
<td>   abstracts a raw device <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_istream.html" title="cpp/io/basic istream"> basic_istream</a></div></div>
</td>
<td>   wraps a given abstract device (<span class="mw-geshi cpp source-cpp"><a href="io/basic_streambuf.html"><span class="kw1331">std::<span class="me2">basic_streambuf</span></span></a></span>)<br> and provides high-level input interface <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_ostream.html" title="cpp/io/basic ostream"> basic_ostream</a></div></div>
</td>
<td>   wraps a given abstract device (<span class="mw-geshi cpp source-cpp"><a href="io/basic_streambuf.html"><span class="kw1331">std::<span class="me2">basic_streambuf</span></span></a></span>)<br> and provides high-level output interface <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_iostream.html" title="cpp/io/basic iostream"> basic_iostream</a></div></div>
</td>
<td>   wraps a given abstract device (<span class="mw-geshi cpp source-cpp"><a href="io/basic_streambuf.html"><span class="kw1331">std::<span class="me2">basic_streambuf</span></span></a></span>)<br> and provides high-level input/output interface <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2"> <h5> <span class="mw-headline" id="File_I.2F0_implementation">  File I/0 implementation </span>
</h5>
</td></tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_filebuf.html" title="cpp/io/basic filebuf"> basic_filebuf</a></div></div>
</td>
<td>   implements raw file device <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_ifstream.html" title="cpp/io/basic ifstream"> basic_ifstream</a></div></div>
</td>
<td>   implements high-level file stream input operations <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_ofstream.html" title="cpp/io/basic ofstream"> basic_ofstream</a></div></div>
</td>
<td>   implements high-level file stream output operations <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_fstreamhtml.html" title="cpp/io/basic fstream"> basic_fstream</a></div></div>
</td>
<td>   implements high-level file stream input/output operations <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2"> <h5> <span class="mw-headline" id="String_I.2F0_implementation">  String I/0 implementation </span>
</h5>
</td></tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_stringbuf.html" title="cpp/io/basic stringbuf"> basic_stringbuf</a></div></div>
</td>
<td>   implements raw string device <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_istringstream.html" title="cpp/io/basic istringstream"> basic_istringstream</a></div></div>
</td>
<td>   implements high-level string stream input operations <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_ostringstream.html" title="cpp/io/basic ostringstream"> basic_ostringstream</a></div></div>
</td>
<td>   implements high-level string stream output operations <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/basic_stringstream.html" title="cpp/io/basic stringstream"> basic_stringstream</a></div></div>
</td>
<td>   implements high-level string stream input/output operations <br><span class="t-mark">(class template)</span>
</td>
</tr>
<tr><td colspan="2"> <h5> <span class="mw-headline" id="Array_I.2FO_implementations">  Array I/O implementations </span>
</h5>
</td></tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div">
<div><a href="io/strstreambuf.html" title="cpp/io/strstreambuf"> strstreambuf</a></div>
<div><span class="t-mark">(deprecated)</span></div>
</div>
</td>
<td>   implements raw character array device <br><span class="t-mark">(class)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div">
<div><a href="io/istrstreamhtml.html" title="cpp/io/istrstream"> istrstream</a></div>
<div><span class="t-mark">(deprecated)</span></div>
</div>
</td>
<td>   implements character array input operations <br><span class="t-mark">(class)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div">
<div><a href="io/ostrstream.html" title="cpp/io/ostrstream"> ostrstream</a></div>
<div><span class="t-mark">(deprecated)</span></div>
</div>
</td>
<td>   implements character array output operations <br><span class="t-mark">(class)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div">
<div><a href="io/strstream.html" title="cpp/io/strstream"> strstream</a></div>
<div><span class="t-mark">(deprecated)</span></div>
</div>
</td>
<td>   implements character array input/output operations <br><span class="t-mark">(class)</span>
</td>
</tr>
</table>
<h4>
<span class="editsection">[<a href="http://en.cppreference.com/mwiki/index.php?title=cpp/io&amp;action=edit&amp;section=2" title="Edit section: Typedefs">edit</a>]</span> <span class="mw-headline" id="Typedefs">Typedefs</span>
</h4>
<p>The following typedefs for common character types are provided:
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">typedef</span> basic_ios<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>                ios<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_ios<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span>            wios<span class="sy4">;</span>
 
<span class="kw1">typedef</span> basic_streambuf<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>     streambuf<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_streambuf<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span> wstreambuf<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_filebuf<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>         filebuf<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_filebuf<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span>     wfilebuf<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_stringbuf<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>     stringbuf<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_stringbuf<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span> wstringbuf<span class="sy4">;</span>
 
<span class="kw1">typedef</span> basic_istream<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>         istream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_istream<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span>     wistream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_ostream<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>         ostream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_ostream<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span>     wostream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_iostream<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>       iostream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_iostream<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span>   wiostream<span class="sy4">;</span>
 
<span class="kw1">typedef</span> basic_ifstream<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>       ifstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_ifstream<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span>   wifstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_ofstream<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>       ofstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_ofstream<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span>   wofstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_fstream<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>         fstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_fstream<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span>     wfstream<span class="sy4">;</span>
 
<span class="kw1">typedef</span> basic_istringstream<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>     istringstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_istringstream<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span> wistringstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_ostringstream<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>     ostringstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_ostringstream<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span> wostringstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_stringstream<span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span>       stringstream<span class="sy4">;</span>
<span class="kw1">typedef</span> basic_stringstream<span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span>   wstringstream<span class="sy4">;</span></pre></div></div>
<p>Predefined standard stream objects:
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">extern</span>  istream  cin<span class="sy4">;</span>   <span class="co1">//standard input (stdin)</span>
<span class="kw4">extern</span> wistream wcin<span class="sy4">;</span>
<span class="kw4">extern</span>  ostream  cout<span class="sy4">;</span>  <span class="co1">//standard output (stdout)</span>
<span class="kw4">extern</span> wostream wcout<span class="sy4">;</span>
<span class="kw4">extern</span>  ostream  cerr<span class="sy4">;</span>  <span class="co1">//standard error (stderr)</span>
<span class="kw4">extern</span> wostream wcerr<span class="sy4">;</span>
<span class="kw4">extern</span>  ostream  clog<span class="sy4">;</span>  <span class="co1">//standard log (stdlog)</span>
<span class="kw4">extern</span> wostream wclog<span class="sy4">;</span></pre></div></div>
<h4>
<span class="editsection">[<a href="http://en.cppreference.com/mwiki/index.php?title=cpp/io&amp;action=edit&amp;section=3" title="Edit section: I/O Manipulators">edit</a>]</span> <span class="mw-headline" id="I.2FO_Manipulators"><a href="io/manip.html" title="cpp/io/manip">I/O Manipulators</a></span>
</h4>
<p>The stream-based I/O library uses <a href="io/manip.html" title="cpp/io/manip"> I/O manipulators</a> (e.g. <span class="mw-geshi cpp source-cpp"><a href="io/manip/boolalpha.html"><span class="kw1424">std::<span class="me2">boolalpha</span></span></a></span>, <span class="mw-geshi cpp source-cpp"><a href="io/manip/hex.html"><span class="kw1442">std::<span class="me2">hex</span></span></a></span>, etc.) to control how streams behave.
</p>
<h4>
<span class="editsection">[<a href="http://en.cppreference.com/mwiki/index.php?title=cpp/io&amp;action=edit&amp;section=4" title="Edit section: Types">edit</a>]</span> <span class="mw-headline" id="Types">Types</span>
</h4>
<p>The following auxiliary type are defined:
</p>
<table class="t-dcl-list-begin">
<tr class="t-dcl-list-header"><td colspan="2"> <div>Defined in header <tt>&lt;ios&gt;</tt> </div>
</td></tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/streamoffhtml.html" title="cpp/io/streamoff"> streamoff</a></div></div>
</td>
<td>   represents relative file/stream position (offset from fpos), sufficient to represent any file size  <br><span class="t-mark">(typedef)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/streamsize.html" title="cpp/io/streamsize"> streamsize</a></div></div>
</td>
<td>   represents the number of characters transferred in an I/O operation or the size of an I/O buffer <br><span class="t-mark">(typedef)</span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div"><div><a href="io/fpos.html" title="cpp/io/fpos"> fpos</a></div></div>
</td>
<td>   represents absolute position in a stream or a file <br><span class="t-mark">(class template)</span>
</td>
</tr>
</table>
<p>Four specializations of <span class="mw-geshi cpp source-cpp"><a href="io/fpos.html"><span class="kw1464">std::<span class="me2">fpos</span></span></a></span> are provided: 
</p>
<table class="t-dcl-list-begin">
<tr class="t-dcl-list-header"><td colspan="2"> <div>Defined in header <tt>&lt;ios&gt;</tt> </div>
</td></tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-hitem">
<td>  Type
</td>
<td>  Definition
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <tt>streampos</tt>
</td>
<td>  <span class="mw-geshi cpp source-cpp"><a href="io/fpos.html"><span class="kw1464">std::<span class="me2">fpos</span></span></a><span class="sy1">&lt;</span><a href="string/char_traits.html"><span class="kw1053">std::<span class="me2">char_traits</span></span></a><span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">state_type</span><span class="sy1">&gt;</span></span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <tt>u16streampos</tt>
</td>
<td>  <span class="mw-geshi cpp source-cpp"><a href="io/fpos.html"><span class="kw1464">std::<span class="me2">fpos</span></span></a><span class="sy1">&lt;</span><a href="string/char_traits.html"><span class="kw1053">std::<span class="me2">char_traits</span></span></a><span class="sy1">&lt;</span><span class="kw4">char16_t</span><span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">state_type</span><span class="sy1">&gt;</span></span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <tt>u32streampos</tt>
</td>
<td>  <span class="mw-geshi cpp source-cpp"><a href="io/fpos.html"><span class="kw1464">std::<span class="me2">fpos</span></span></a><span class="sy1">&lt;</span><a href="string/char_traits.html"><span class="kw1053">std::<span class="me2">char_traits</span></span></a><span class="sy1">&lt;</span><span class="kw4">char32_t</span><span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">state_type</span><span class="sy1">&gt;</span></span>
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <tt>wstreampos</tt>
</td>
<td>  <span class="mw-geshi cpp source-cpp"><a href="io/fpos.html"><span class="kw1464">std::<span class="me2">fpos</span></span></a><span class="sy1">&lt;</span><a href="string/char_traits.html"><span class="kw1053">std::<span class="me2">char_traits</span></span></a><span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">state_type</span><span class="sy1">&gt;</span></span>
</td>
</tr>
</table>
<h4>
<span class="editsection">[<a href="http://en.cppreference.com/mwiki/index.php?title=cpp/io&amp;action=edit&amp;section=5" title="Edit section: Error category interface">edit</a>]</span> <span class="mw-headline" id="Error_category_interface">Error category interface</span>
</h4>
<table class="t-dcl-list-begin">
<tr class="t-dcl-list-header"><td colspan="2"> <div>Defined in header <tt>&lt;ios&gt;</tt> </div>
</td></tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div">
<div><a href="io/io_errc.html" title="cpp/io/io errc"> io_errc</a></div>
<div><span class="t-mark">(C++11)</span></div>
</div>
</td>
<td>   the IO stream error codes <br><span class="t-mark">(enum)</span> 
</td>
</tr>
<tr><td colspan="2" class="t-dcl-list-sep">
</td></tr>
<tr class="t-dcl-list-item">
<td>  <div class="t-dcl-member-div">
<div><a href="io/iostream_categoryhtml.html" title="cpp/io/iostream category"> iostream_category</a></div>
<div><span class="t-mark">(C++11)</span></div>
</div>
</td>
<td>   identifies the iostream error category <br><span class="t-mark">(function)</span> 
</td>
</tr>
</table>
<h3>
<span class="editsection">[<a href="http://en.cppreference.com/mwiki/index.php?title=cpp/io&amp;action=edit&amp;section=6" title="Edit section: C-style IO">edit</a>]</span> <span class="mw-headline" id="C-style_IO"><a href="io/c.html" title="cpp/io/c"> C-style IO</a></span>
</h3>
<p>C++ also includes the <a href="io/c.html" title="cpp/io/c"> input/output functions defined by C</a>, such as <span class="mw-geshi cpp source-cpp"><a href="io/c/fopenhtml.html"><span class="kw1471">std::<span class="me2">fopen</span></span></a></span>, <span class="mw-geshi cpp source-cpp"><a href="io/c/fgetc.html"><span class="kw1480">std::<span class="me2">getc</span></span></a></span>, etc.
</p>
<!-- 
NewPP limit report
Preprocessor node count: 3452/1000000
Post-expand include size: 79949/2097152 bytes
Template argument size: 31317/2097152 bytes
Expensive parser function count: 0/100
-->

<!-- Saved in parser cache with key mwiki1-mwiki_en_:pcache:idhash:476-0!*!0!!en!2!* and timestamp 20120615232734 -->
</div>                    <!-- /bodycontent -->
                                        <!-- printfooter -->
                    <div class="printfooter">
                    Retrieved from "<a href="http://en.cppreference.com/mwiki/index.php?title=cpp/io&amp;oldid=33661">http://en.cppreference.com/mwiki/index.php?title=cpp/io&amp;oldid=33661</a>"                    </div>
                    <!-- /printfooter -->
                                                            <!-- catlinks -->
                    <div id="catlinks" class="catlinks catlinks-allhidden"></div>                    <!-- /catlinks -->
                                                            <div class="visualClear"></div>
                    <!-- debughtml -->
                                        <!-- /debughtml -->
                </div>
                <!-- /bodyContent -->
            </div>
        </div>
        <!-- /content -->
        <!-- footer -->
        
        <!-- /footer -->
        <script src="../../common/loadac2a.php?debug=false&amp;lang=en&amp;modules=skins.cppreference2&amp;only=scripts&amp;skin=cppreference2&amp;*"></script><script>if(window.mw){
	mw.loader.load(["mediawiki.user", "mediawiki.util", "mediawiki.page.ready", "mediawiki.legacy.wikibits", "mediawiki.legacy.ajax"]);
}
</script><script src="../../common/load345b.php?debug=false&amp;lang=en&amp;modules=site&amp;only=scripts&amp;skin=cppreference2&amp;*"></script><script>if(window.mw){
	mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":0,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"highlightbroken":1,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":0,"showjumplinks":1,"shownumberswatching":1,"showtoc":0,"showtoolbar":1,"skin":"cppreference2","stubthreshold":0,"thumbsize":2,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":0,"watchdefault":0,"watchdeletion":0,"watchlistdays":3,"watchlisthideanons":0
	,"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"variant":"en","language":"en","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false});;mw.user.tokens.set({"editToken":"+\\","watchToken":false});;mw.loader.state({"user.options":"ready","user.tokens":"ready"});
	
	/* cache key: mwiki1-mwiki_en_:resourceloader:filter:minify-js:4:3740695a1552aee37d594967bd36f869 */
}
</script><script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
var pageTracker = _gat._getTracker("UA-2828341-1");
pageTracker._trackPageview();
</script><!-- Served in 2.930 secs. -->
</body>
<!-- Cached 20120615232735 -->
</html>
