The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
 lang="en" dir="ltr">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>
    C++ I/O    [C++ Reference]
  </title>

  <meta name="generator" content="DokuWiki Release 2009-12-25c &quot;Lemming&quot;" />
<meta name="robots" content="index,follow" />
<meta name="date" content="2010-04-18T22:30:09-0700" />
<meta name="keywords" content="io,start" />
<link rel="search" type="application/opensearchdescription+xml" href="/wiki/lib/exe/opensearch.php" title="C++ Reference" />
<link rel="start" href="/wiki/" />
<link rel="contents" href="/wiki/io/start?do=index" title="Index" />
<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="/wiki/feed.php" />
<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="/wiki/feed.php?mode=list&amp;ns=io" />
<link rel="edit" title="Edit this page" href="/wiki/io/start?do=edit" />
<link rel="alternate" type="text/html" title="Plain HTML" href="/wiki/_export/xhtml/io/start" />
<link rel="alternate" type="text/plain" title="Wiki Markup" href="/wiki/_export/raw/io/start" />
<link rel="canonical" href="http://www.cppreference.com/wiki/io/start" />
<link rel="stylesheet" media="all" type="text/css" href="/wiki/lib/exe/css.php?s=all&amp;t=custom1&amp;tseed=1272971091" />
<link rel="stylesheet" media="screen" type="text/css" href="/wiki/lib/exe/css.php?t=custom1&amp;tseed=1272971091" />
<link rel="stylesheet" media="print" type="text/css" href="/wiki/lib/exe/css.php?s=print&amp;t=custom1&amp;tseed=1272971091" />
<script type="text/javascript" charset="utf-8" ><!--//--><![CDATA[//><!--
var NS='io';var JSINFO = {"id":"io:start","namespace":"io"};
//--><!]]></script>
<script type="text/javascript" charset="utf-8" src="/wiki/lib/exe/js.php?tseed=1272971091" ></script>

  <link rel="shortcut icon" href="/wiki/lib/tpl/custom1/images/favicon.png" />

  </head>

<body>
<div class="dokuwiki">
  
  <div class="stylehead">

    <div class="header">
      <div class="pagename">
        [[<a href="../io/start.html"  title="Backlinks">C++ I/O</a>]]
      </div>
      <div class="logo">
        <a href="http://www.cppreference.com"  name="dokuwiki__top" id="dokuwiki__top" accesskey="h" title="[ALT+H]">C++ Reference</a>      </div>

      <div class="clearer"></div>
    </div>

    
    
        <div class="breadcrumbs">
      <span class="bchead">You are here: </span><a href="../start.html"  title="start">C++ Reference</a> &raquo; <a href="../io/start.html"  title="io:start">C++ I/O</a>    </div>
    
  </div>

<div class="plugin_translation"><span>Translations of this page<sup><a href="../localization.html" class="wikilink1" title="localization">?</a></sup>:</span> <ul>  <li><div class="li"><span class="curid"><a href="../io/start.html" class="wikilink1" title="io:start">en</a></span></div></li>  <li><div class="li"><a href="../br-pt/io/start.html" class="wikilink2" title="br-pt:io:start" rel="nofollow">br-pt</a></div></li>  <li><div class="li"><a href="../cn/io/start.html" class="wikilink1" title="cn:io:start">cn</a></div></li>  <li><div class="li"><a href="../cz/io/start.html" class="wikilink2" title="cz:io:start" rel="nofollow">cz</a></div></li>  <li><div class="li"><a href="../de/io/start.html" class="wikilink2" title="de:io:start" rel="nofollow">de</a></div></li>  <li><div class="li"><a href="../es/io/start.html" class="wikilink2" title="es:io:start" rel="nofollow">es</a></div></li>  <li><div class="li"><a href="../fr/io/start.html" class="wikilink2" title="fr:io:start" rel="nofollow">fr</a></div></li>  <li><div class="li"><a href="../it/io/start.html" class="wikilink1" title="it:io:start">it</a></div></li>  <li><div class="li"><a href="../jp/io/start.html" class="wikilink1" title="jp:io:start">jp</a></div></li>  <li><div class="li"><a href="../nl/io/start.html" class="wikilink2" title="nl:io:start" rel="nofollow">nl</a></div></li>  <li><div class="li"><a href="../pl/io/start.html" class="wikilink1" title="pl:io:start">pl</a></div></li>  <li><div class="li"><a href="../ro/io/start.html" class="wikilink2" title="ro:io:start" rel="nofollow">ro</a></div></li>  <li><div class="li"><a href="../ru/io/start.html" class="wikilink2" title="ru:io:start" rel="nofollow">ru</a></div></li>  <li><div class="li"><a href="../sk/io/start.html" class="wikilink2" title="sk:io:start" rel="nofollow">sk</a></div></li>  <li><div class="li"><a href="../tr/io/start.html" class="wikilink2" title="tr:io:start" rel="nofollow">tr</a></div></li>  <li><div class="li"><a href="../tw/io/start.html" class="wikilink2" title="tw:io:start" rel="nofollow">tw</a></div></li></ul></div>
  
  
  <div class="page">

    <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
    <!-- wikipage start -->
    


<h1><a name="c_io" id="c_io">C++ I/O</a></h1>
<div class="level1">

<p>

The &lt;iostream&gt; library automatically defines a few standard objects:

</p>
<ul>
<li class="level1"><div class="li"> cout, an object of the ostream class, which displays data to the standard output device.</div>
</li>
<li class="level1"><div class="li"> cerr, another object of the ostream class that writes unbuffered output to the standard error device.</div>
</li>
<li class="level1"><div class="li"> clog, like cerr, but uses buffered output.</div>
</li>
<li class="level1"><div class="li"> cin, an object of the istream class that reads data from the standard input device.</div>
</li>
</ul>

<p>

The &lt;fstream&gt; library allows programmers to do file input and output
with the ifstream and ofstream classes.  C++ programmers can also do
input and output from strings by using the <a href="../io/sstream/start.html" class="wikilink1" title="io:sstream:start">stringstream</a> class.
</p>

<p>
Some of the behavior of the C++ I/O streams (precision, justification,
etc) may be modified by manipulating various <a href="../io/io_flags.html" class="wikilink1" title="io:io_flags">I/O stream
format flags</a>.
</p>
<table class="inline">
	<tr class="row0">
		<td class="col0"><a href="../io/constructors.html" class="wikilink1" title="io:constructors">I/O Constructors</a></td><td class="col1">constructors</td>
	</tr>
	<tr class="row1">
		<td class="col0"><a href="../io/bad.html" class="wikilink1" title="io:bad">bad</a></td><td class="col1">true if an error occurred</td>
	</tr>
	<tr class="row2">
		<td class="col0"><a href="../io/clear.html" class="wikilink1" title="io:clear">clear</a></td><td class="col1">clear and set status flags</td>
	</tr>
	<tr class="row3">
		<td class="col0"><a href="../io/close.html" class="wikilink1" title="io:close">close</a></td><td class="col1">close a stream</td>
	</tr>
	<tr class="row4">
		<td class="col0"><a href="../io/eof.html" class="wikilink1" title="io:eof">eof</a></td><td class="col1">true if at the end-of-file</td>
	</tr>
	<tr class="row5">
		<td class="col0"><a href="../io/exceptions.html" class="wikilink1" title="io:exceptions">exceptions</a></td><td class="col1">set the stream to throw exceptions on errors</td>
	</tr>
	<tr class="row6">
		<td class="col0"><a href="../io/fail.html" class="wikilink1" title="io:fail">fail</a></td><td class="col1">true if an error occurred</td>
	</tr>
	<tr class="row7">
		<td class="col0"><a href="../io/fill.html" class="wikilink1" title="io:fill">fill</a></td><td class="col1">manipulate the default fill character</td>
	</tr>
	<tr class="row8">
		<td class="col0"><a href="../io/flags.html" class="wikilink1" title="io:flags">flags</a></td><td class="col1">access or manipulate io_stream_format_flags</td>
	</tr>
	<tr class="row9">
		<td class="col0"><a href="../io/flush.html" class="wikilink1" title="io:flush">flush</a></td><td class="col1">empty the buffer</td>
	</tr>
	<tr class="row10">
		<td class="col0"><a href="../io/gcount.html" class="wikilink1" title="io:gcount">gcount</a></td><td class="col1">number of characters read during last input</td>
	</tr>
	<tr class="row11">
		<td class="col0"><a href="../io/get.html" class="wikilink1" title="io:get">get</a></td><td class="col1">read characters</td>
	</tr>
	<tr class="row12">
		<td class="col0"><a href="../io/getline.html" class="wikilink1" title="io:getline">getline</a></td><td class="col1">read a line of characters</td>
	</tr>
	<tr class="row13">
		<td class="col0"><a href="../io/good.html" class="wikilink1" title="io:good">good</a></td><td class="col1">true if no errors have occurred</td>
	</tr>
	<tr class="row14">
		<td class="col0"><a href="../io/ignore.html" class="wikilink1" title="io:ignore">ignore</a></td><td class="col1">read and discard characters</td>
	</tr>
	<tr class="row15">
		<td class="col0"><a href="../io/is_open.html" class="wikilink1" title="io:is_open">is_open</a></td><td class="col1">check if a file is open</td>
	</tr>
	<tr class="row16">
		<td class="col0"><a href="../io/open.html" class="wikilink1" title="io:open">open</a></td><td class="col1">open a new stream</td>
	</tr>
	<tr class="row17">
		<td class="col0"><a href="../io/peek.html" class="wikilink1" title="io:peek">peek</a></td><td class="col1">check the next input character</td>
	</tr>
	<tr class="row18">
		<td class="col0"><a href="../io/precision.html" class="wikilink1" title="io:precision">precision</a></td><td class="col1">manipulate the precision of a stream</td>
	</tr>
	<tr class="row19">
		<td class="col0"><a href="../io/put.html" class="wikilink1" title="io:put">put</a></td><td class="col1">write characters</td>
	</tr>
	<tr class="row20">
		<td class="col0"><a href="../io/putback.html" class="wikilink1" title="io:putback">putback</a></td><td class="col1">return characters to a stream</td>
	</tr>
	<tr class="row21">
		<td class="col0"><a href="../io/rdstate.html" class="wikilink1" title="io:rdstate">rdstate</a></td><td class="col1">returns the state flags of the stream</td>
	</tr>
	<tr class="row22">
		<td class="col0"><a href="../io/read.html" class="wikilink1" title="io:read">read</a></td><td class="col1">read data into a buffer</td>
	</tr>
	<tr class="row23">
		<td class="col0"><a href="../io/seekg.html" class="wikilink1" title="io:seekg">seekg</a></td><td class="col1">perform random access on an input stream</td>
	</tr>
	<tr class="row24">
		<td class="col0"><a href="../io/seekp.html" class="wikilink1" title="io:seekp">seekp</a></td><td class="col1">perform random access on output streams</td>
	</tr>
	<tr class="row25">
		<td class="col0"><a href="../io/setf.html" class="wikilink1" title="io:setf">setf</a></td><td class="col1">set format flags</td>
	</tr>
	<tr class="row26">
		<td class="col0"><a href="../io/sync_with_stdio.html" class="wikilink1" title="io:sync_with_stdio">sync_with_stdio</a></td><td class="col1">synchronize with standard I/O</td>
	</tr>
	<tr class="row27">
		<td class="col0"><a href="../io/tellg.html" class="wikilink1" title="io:tellg">tellg</a></td><td class="col1">read input stream pointers</td>
	</tr>
	<tr class="row28">
		<td class="col0"><a href="../io/tellp.html" class="wikilink1" title="io:tellp">tellp</a></td><td class="col1">read output stream pointers</td>
	</tr>
	<tr class="row29">
		<td class="col0"><a href="../io/unsetf.html" class="wikilink1" title="io:unsetf">unsetf</a></td><td class="col1">clear io_stream_format_flags</td>
	</tr>
	<tr class="row30">
		<td class="col0"><a href="../io/width.html" class="wikilink1" title="io:width">width</a></td><td class="col1">access and manipulate the minimum field width</td>
	</tr>
	<tr class="row31">
		<td class="col0"><a href="../io/write.html" class="wikilink1" title="io:write">write</a></td><td class="col1">write characters</td>
	</tr>
</table>

</div>

    <!-- wikipage stop -->
  </div>

  <div class="clearer">&nbsp;</div>

  
  <div class="stylefoot">

    <div class="meta">
      <div class="user">
              </div>
      <!--
      <div class="doc">
        io/start.txt &middot; Last modified: 04/18/2010 22:30 by dnglaze      </div>
      -->
    </div>

   
    <div class="bar" id="bar__bottom">
      <div class="bar-left" id="bar__bottomleft">
        <a href="../io/start.html"  class="action edit" accesskey="e" rel="nofollow">Edit this page</a> &#149;
        <a href="../io/start.html"  class="action revisions" accesskey="o" rel="nofollow">Old revisions</a>      </div>
      <div class="bar-right" id="bar__bottomright">
         &#149;
         &#149;
         &#149;
        <a href="../io/start.html"  class="action login" rel="nofollow">Login</a> &#149;
        <a href="../io/start.html"  class="action index" accesskey="x" rel="nofollow">Index</a> &#149;
        <a href="../io/start.html"  class="action recent" accesskey="r" rel="nofollow">Recent changes</a> &#149;
        <a  href="../feed.php.html" title="Recent changes RSS feed">RSS</a> &#149;
        <a href='http://creativecommons.org/licenses/by/3.0/us/' title='Creative Commons license'>cc</a> &#149;
        <form action="/wiki/" accept-charset="utf-8" class="search" id="dw__search"><div class="no"><input type="hidden" name="do" value="search" /><input type="text" id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" /><input type="submit" value="Search" class="button" title="Search" /><div id="qsearch__out" class="ajax_qsearch JSpopup"></div></div></form>&nbsp;
      </div>
      <div class="clearer"></div>
    </div>

  </div>

</div>

<div class="no"><img src="/wiki/lib/exe/indexer.php?id=io%3Astart&amp;1273193081" width="1" height="1" alt=""  /></div>
</body>
</html>