📄 cppio_details.html
字号:
<H2> <A NAME="precision">precision</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> streamsize precision(); streamsize precision( streamsize p );</PRE></TD></TR></TABLE><P> precision()函数设置或返回当前要被显示的浮点变量的位数。例如,下面的代码:</P><PRE> float num = 314.15926535; cout.precision( 5 ); cout << num;</PRE><P> displays</P><PRE> 314.16</PRE><I>相关主题:</I><BR><STRONG><A HREF="#width">width()</A>, <A HREF="#fill">fill()</A> </STRONG><HR><H2> <A NAME="put">put</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> ostream &put( char ch );</PRE></TD></TR></TABLE><P> 函数put()用于输出流,并把字符<I>ch</I>写入流中。</P><I>相关主题:</I><BR><STRONG><A HREF="#write">write()</A>, <A HREF="#get">get()</A> </STRONG><HR><H2> <A NAME="putback">putback</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> istream &putback( char ch );</PRE></TD></TR></TABLE><P> putback()函数用于输入流,并且返回以前读的字符<I>ch</I>到输入流中。</P><I>相关主题:</I><BR><STRONG><A HREF="#peek">peek()</A> </STRONG><HR><H2> <A NAME="rdstate">rdstate</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> iostate rdstate();</PRE></TD></TR></TABLE><P> rdstate()函数返回当前流的状态。<STRONG>iostate</STRONG> 对象有下面这些标志:</P><TABLE> <TR><TH>标志</TH><TH>含义</TH></TR> <TR BGCOLOR="EEEEFF"><TD>badbit</TD><TD>发生致命的错误</TD></TR> <TR><TD>eofbit</TD><TD>已经发现EOF</TD></TR> <TR BGCOLOR="EEEEFF"><TD>failbit</TD><TD>一个非致命性错误已经发生</TD></TR> <TR><TD>goodbit</TD><TD>没有发生错误</TD></TR></TABLE><P><I>相关主题:</I><BR><STRONG><A HREF="#eof">eof()</A>, <A HREF="#good">good()</A>, <A HREF="#bad">bad()</A>, <A HREF="#clear">clear()</A>, <A HREF="#fail">fail()</A></STRONG></P><HR><H2> <A NAME="read">read</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> istream &read( char *buffer, streamsize num );</PRE></TD></TR></TABLE><P> 函数read()用于输入流,在将字符放入<I>buffer</I> 之前从流中读取<I>num</I> 个字节。如果碰到EOF,read()中止,丢弃不论多少个字节已经放入。例如:</P><PRE> struct { int height; int width; } rectangle; input_file.read( (char *)(&rectangle), sizeof(rectangle) ); if( input_file.bad() ) { cerr << "Error reading data" << endl; exit( 0 ); }</PRE><I>相关主题:</I><BR><STRONG><A HREF="#gcount">gcount()</A>, <A HREF="#get">get()</A>, <A HREF="#getline">getline()</A>, <A HREF="#write">write()</A> </STRONG><HR><H2> <A NAME="seekg">seekg</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> istream &seekg( off_type offset, ios::seekdir origin ); istream &seekg( pos_type position );</PRE></TD></TR></TABLE><P> 函数seekg()用于输入流,并且它将重新设置"get"指针到当前流的从<I>origin</I>偏移<I>offset</I>个字节的位置上,或是置"get"指针在<I>position</I>位置。</P><I>相关主题:</I><BR><STRONG><A HREF="#seekp">seekp()</A>, <A HREF="#tellg">tellg()</A>, <A HREF="#tellp">tellp()</A> </STRONG><HR><H2> <A NAME="seekp">seekp</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> ostream &seekp( off_type offset, ios::seekdir origin ); ostream &seekp( pos_type position );</PRE></TD></TR></TABLE><P> seekp()函数用于输出流,但在其它方面和<A HREF="#seekg">seekg()</A>很类似。</P><I>相关主题:</I><BR><STRONG><A HREF="#seekg">seekg()</A>, <A HREF="#tellg">tellg()</A>, <A HREF="#tellp">tellp()</A> </STRONG><HR><H2> <A NAME="setf">setf</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> fmtflags setf( fmtflags flags ); fmtflags setf( fmtflags flags, fmtflags needed );</PRE></TD></TR></TABLE><P> 函数setf()设置当前流的<A HREF="cppio_flags.html">格式化标志</A>为<I>flags</I>。可选标志<I>needed</I> 只允许<I>flags</I>标志和<I>needed</I>标志都被设置。返回值是前面设置的标志。<br> 例如:</P><PRE> int number = 0x3FF; cout.setf( ios::dec ); cout << "Decimal: " << number << endl; cout.unsetf( ios::dec ); cout.setf( ios::hex ); cout << "Hexadecimal: " << number << endl;</PRE><P> 提示,上面的代码和下面的代码的功能是一致的:</P><PRE> int number = 0x3FF; cout << "Decimal: " << number << endl << hex << "Hexadecimal: " << number << dec << endl;</PRE><P> 参考 <A HREF="cppio_flags.html">manipulators</A>.</P><I>相关主题:</I><BR><STRONG><A HREF="#flags">flags()</A>, <A HREF="#unsetf">unsetf()</A> </STRONG><HR><H2> <A NAME="sync_with_stdio">sync_with_stdio</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> static bool sync_with_stdio( bool sync=true );</PRE></TD></TR></TABLE><P> sync_with_stdio()函数有打开或关闭使用C++风格I/O系统混合C风格的I/O系统的功能。 </P><HR><H2> <A NAME="tellg">tellg</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> pos_type tellg();</PRE></TD></TR></TABLE><P> tellg()函数用于输入流,并返回流中"get"指针的当前位置。</P><I>相关主题:</I><BR><STRONG><A HREF="#seekg">seekg()</A>, <A HREF="#seekp">seekp()</A>, <A HREF="#tellp">tellp()</A> </STRONG><HR><H2> <A NAME="tellp">tellp</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> pos_type tellp();</PRE></TD></TR></TABLE><P> tellp()函数用于输出流中,并返回在流中当前"put"指针的位置。 例如,下面的代码显示了当一个文件指针写入一个流的时候的情形:</P><PRE> string s("In Xanadu did Kubla Khan..."); ofstream fout("output.txt"); for( int i=0; i < s.length(); i++ ) { cout << "File pointer: " << fout.tellp(); fout.put( s[i] ); cout << " " << s[i] << endl; } fout.close();</PRE><I>相关主题:</I><BR><STRONG><A HREF="#seekg">seekg()</A>, <A HREF="#seekp">seekp()</A>, <A HREF="#tellg">tellg()</A> </STRONG><HR><H2> <A NAME="unsetf">unsetf</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> void unsetf( fmtflags flags );</PRE></TD></TR></TABLE><P> 函数unsetf()用于清除与当前流相关的给定的标志<I>flags</I>。<A HREF="cppio_flags.html">什么标志呢?</A></P><I>相关主题:</I><BR><STRONG><A HREF="#setf">setf()</A>, <A HREF="#flags">flags()</A> </STRONG><HR><H2> <A NAME="width">width</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> int width(); int width( int w );</PRE></TD></TR></TABLE><P> 函数 width()返回当前的宽度。可选择参数<I>w</I>用于设定宽度大小。宽度是指每一次输出中显示的字符的最小数目。例如:</P><PRE> cout.width( 5 ); cout << "2";</PRE><P> displays</P><PRE> 2</PRE><P> (在一个'2'的后面紧跟着四个空格)</P><I>相关主题:</I><BR><STRONG><A HREF="#precision">precision()</A>, <A HREF="#fill">fill()</A> </STRONG><HR><H2> <A NAME="write">write</A></H2><I>语法:</I><TABLE BGCOLOR="CCCCFF"><TR><TD><PRE> ostream &write( const char *buffer, streamsize num );</PRE></TD></TR></TABLE><P> write()函数用于输出流,从<i>buffer</i>中写<i>num</i>个字节到当前输出流中。</P><I>相关主题:</I><BR><STRONG><A HREF="#read">read()</A>, <A HREF="#put">put()</A> </BODY></HTML><br><html>
<head>
<meta http-equiv='Content-Type' content='text/html' charset='ISO_8859_1'>
<title>232</title>
<style>
<!--
div#StrBanner /* Creates Nonscrolling banner region */
{
position: relative;
left: 0px;
padding: 0px 0px 0px 0px;
border-bottom: 1px solid #999999;
background-color: #99ccff;
}
div#titlerow /* <!-- 232 --> */
{
padding: 0px 10px 0px 22px;
}
h1, h2, h3, h4 /* <!-- 232 --> */
{
font-family: Verdana, Arial, Helvetica, sans-serif;
margin-bottom: .4em;
margin-top: 0em;
font-weight: bold;
}
-->
</style>
</head>
<body><!-- 232 -->
<div id='StrBanner'>
<div>
<table class='TableBanner' cellspacing='0'>
<tr>
<td ALIGN=RIGHT><!-- 232 --></td>
<td ALIGN=RIGHT><!-- 232 --></td> </tr>
</table>
</div>
<div id='TitleRow'>
<h3>Extr<!-- 232 -->acted by <!-- 232 -->Tria<!-- 232 -->l version of Ch<!-- 232 -->mDecom<!-- 232 -->piler<!-- 232 --> (<a href="http://www.etextwizard.com/download/cd/cdsetup.exe" target=_blank>Download Now</a>).</h3>
<h4>Once reg<!-- 232 -->istered, <!-- 232 -->all restrictions of the Tr<!-- 232 -->ial version are removed.</h4>
<a href="http://www.zipghost.com/order_chmdecompiler.html" target=_blank><H3>B<!-- 232 -->uy Now</H3></a>
</div>
</div>
<p><!-- 232 -->
</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -