⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_20594.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:20594 发表者:挪威的森林 发表日期:2002-11-07 18:11:02
<br>主题:请教
<br>内容:请问PRINTF参数的具体用法<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:Norton AntiVirus 回复日期:2002-11-07 19:55:27
<br>内容:别忘了给分!!!!!<BR><BR><BR><BR>printf, wprintf<BR>Print formatted output to the standard output stream.<BR><BR>int printf( const char *format [, argument]... );<BR><BR>int wprintf( const wchar_t *format [, argument]... );<BR><BR>Routine Required Header Compatibility <BR>printf &lt;stdio.h&gt; ANSI, Win 95, Win NT <BR>wprintf &lt;stdio.h&gt; or &lt;wchar.h&gt; ANSI, Win 95, Win NT <BR><BR><BR>For additional compatibility information, see Compatibility in the Introduction.<BR><BR>Libraries<BR><BR>LIBC.LIB Single thread static library, retail version <BR>LIBCMT.LIB Multithread static library, retail version <BR>MSVCRT.LIB Import library for MSVCRT.DLL, retail version <BR><BR><BR>Return Value<BR><BR>Each of these functions returns the number of characters printed, or a negative value if an error occurs.<BR><BR>Parameters<BR><BR>format<BR><BR>Format control<BR><BR>argument<BR><BR>Optional arguments<BR><BR>Remarks<BR><BR>The printf function formats and prints a series of characters and values to the standard output stream, stdout. If arguments follow the format string, the format string must contain specifications that determine the output format for the arguments. printf and fprintf behave identically except that printf writes output to stdout rather than to a destination of type FILE.<BR><BR>wprintf is a wide-character version of printf; format is a wide-character string. wprintf and printf behave identically otherwise. <BR><BR>Generic-Text Routine Mappings<BR><BR>TCHAR.H Routine&nbsp;&nbsp;_UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined <BR>_tprintf printf printf wprintf <BR><BR><BR>The format argument consists of ordinary characters, escape sequences, and (if arguments follow format) format specifications. The ordinary characters and escape sequences are copied to stdout in order of their appearance. For example, the line<BR><BR>printf("Line one\n\t\tLine two\n"); <BR><BR>produces the output<BR><BR>Line one<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Line two<BR><BR>Format specifications always begin with a percent sign (%) and are read left to right. When printf encounters the first format specification (if any), it converts the value of the first argument after format and outputs it accordingly. The second format specification causes the second argument to be converted and output, and so on. If there are more arguments than there are format specifications, the extra arguments are ignored. The results are undefined if there are not enough arguments for all the format specifications.<BR><BR>Example<BR><BR>/* PRINTF.C: This program uses the printf and wprintf functions<BR> * to produce formatted output.<BR> */<BR><BR>#include &lt;stdio.h&gt;<BR><BR>void main( void )<BR>{<BR>&nbsp;&nbsp; char&nbsp;&nbsp; ch = 'h', *string = "computer";<BR>&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;count = -9234;<BR>&nbsp;&nbsp; double fp = 251.7366;<BR>&nbsp;&nbsp; wchar_t wch = L'w', *wstring = L"Unicode";<BR><BR>&nbsp;&nbsp; /* Display integers. */<BR>&nbsp;&nbsp; printf( "Integer formats:\n"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "\tDecimal: %d&nbsp;&nbsp;Justified: %.6d&nbsp;&nbsp;Unsigned: %u\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count, count, count, count );<BR><BR>&nbsp;&nbsp; printf( "Decimal %d as:\n\tHex: %Xh&nbsp;&nbsp;C hex: 0x%x&nbsp;&nbsp;Octal: %o\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count, count, count, count );<BR><BR>&nbsp;&nbsp; /* Display in different radixes. */<BR>&nbsp;&nbsp; printf( "Digits 10 equal:\n\tHex: %i&nbsp;&nbsp;Octal: %i&nbsp;&nbsp;Decimal: %i\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x10, 010, 10 );<BR><BR>&nbsp;&nbsp; /* Display characters. */<BR><BR>&nbsp;&nbsp; printf("Characters in field (1):\n%10c%5hc%5C%5lc\n", ch, ch, wch, wch);<BR>&nbsp;&nbsp; wprintf(L"Characters in field (2):\n%10C%5hc%5c%5lc\n", ch, ch, wch, wch);<BR><BR>&nbsp;&nbsp; /* Display strings. */<BR><BR>&nbsp;&nbsp; printf("Strings in field (1):\n%25s\n%25.4hs\n\t%S%25.3ls\n",<BR>&nbsp;&nbsp; string, string, wstring, wstring);<BR>&nbsp;&nbsp; wprintf(L"Strings in field (2):\n%25S\n%25.4hs\n\t%s%25.3ls\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string, string, wstring, wstring);<BR><BR>&nbsp;&nbsp; /* Display real numbers. */<BR>&nbsp;&nbsp; printf( "Real numbers:\n\t%f %.2f %e %E\n", fp, fp, fp, fp );<BR><BR>&nbsp;&nbsp; /* Display pointer. */<BR>&nbsp;&nbsp; printf( "\nAddress as:\t%p\n", &count);<BR><BR>&nbsp;&nbsp; /* Count characters printed. */<BR>&nbsp;&nbsp; printf( "\nDisplay to here:\n" );<BR>&nbsp;&nbsp; printf( "1234567890123456%n78901234567890\n", &count );<BR>&nbsp;&nbsp; printf( "\tNumber displayed: %d\n\n", count );<BR>}<BR><BR><BR>Output<BR><BR>Integer formats:<BR>&nbsp;&nbsp; Decimal: -9234&nbsp;&nbsp;Justified: -009234&nbsp;&nbsp;Unsigned: 4294958062<BR>Decimal -9234 as:<BR>&nbsp;&nbsp; Hex: FFFFDBEEh&nbsp;&nbsp;C hex: 0xffffdbee&nbsp;&nbsp;Octal: 37777755756<BR>Digits 10 equal:<BR>&nbsp;&nbsp; Hex: 16&nbsp;&nbsp;Octal: 8&nbsp;&nb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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Uni<BR>Real numbers:<BR>&nbsp;&nbsp; 251.736600 251.74 2.517366e+002 2.517366E+002<BR><BR>Address as:&nbsp;&nbsp; 0012FFAC<BR><BR>Display to here:<BR>123456789012345678901234567890<BR>&nbsp;&nbsp; Number displayed: 16<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -