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

📄 subject_18305.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:18305 发表者:小妮 发表日期:2002-10-19 15:16:36
<br>主题:将long型变量转换成字符型变量的函数哪个啊?
<br>内容:我的程序中需要把将long型变量转换成字符型变量,我记得C中有现成的函数可以实现把long型变量转换成字符型变量,谁知道啊,请告诉我,还有,要使用这个函数需要加载哪个头文件? 
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:凯凯 回复日期:2002-10-19 15:19:15
<br>内容:_ltoa, _ltow<BR>Convert a long integer to a string.<BR><BR>char *_ltoa( long value, char *string, int radix );<BR><BR>wchar_t *_ltow( long value, wchar_t *string, int radix );<BR><BR>Routine Required Header Compatibility <BR>_ltoa &lt;stdlib.h&gt; Win 95, Win NT <BR>_ltow &lt;stdlib.h&gt; 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 a pointer to string. There is no error return.<BR><BR>Parameters<BR><BR>value<BR><BR>Number to be converted<BR><BR>string<BR><BR>String result<BR><BR>radix<BR><BR>Base of value<BR><BR>Remarks<BR><BR>The _ltoa function converts the digits of value to a null-terminated character string and stores the result (up to 33 bytes) in string. The radix argument specifies the base of value, which must be in the range 2 – 36. If radix equals 10 and value is negative, the first character of the stored string is the minus sign (–). _ltow is a wide-character version of _ltoa; the second argument and return value of _ltow are wide-character strings. Each of these functions is Microsoft-specific.<BR><BR>Generic-Text Routine Mappings<BR><BR>TCHAR.H Routine&nbsp;&nbsp;_UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined <BR>_ltot _ltoa _ltoa _ltow <BR><BR><BR>Example<BR><BR>/* ITOA.C: This program converts integers of various<BR> * sizes to strings in various radixes.<BR> */<BR><BR>#include &lt;stdlib.h&gt;<BR>#include &lt;stdio.h&gt;<BR><BR>void main( void )<BR>{<BR>&nbsp;&nbsp; char buffer[20];<BR>&nbsp;&nbsp; int&nbsp;&nbsp;i = 3445;<BR>&nbsp;&nbsp; long l = -344115L;<BR>&nbsp;&nbsp; unsigned long ul = 1234567890UL;<BR><BR>&nbsp;&nbsp; _itoa( i, buffer, 10 );<BR>&nbsp;&nbsp; printf( "String of integer %d (radix 10): %s\n", i, buffer );<BR>&nbsp;&nbsp; _itoa( i, buffer, 16 );<BR>&nbsp;&nbsp; printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );<BR>&nbsp;&nbsp; _itoa( i, buffer, 2&nbsp;&nbsp;);<BR>&nbsp;&nbsp; printf( "String of integer %d (radix 2): %s\n", i, buffer );<BR><BR>&nbsp;&nbsp; _ltoa( l, buffer, 16 );<BR>&nbsp;&nbsp; printf( "String of long int %ld (radix 16): 0x%s\n", l, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer );<BR><BR>&nbsp;&nbsp; _ultoa( ul, buffer, 16 );<BR>&nbsp;&nbsp; printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer );<BR>}<BR><BR><BR>Output<BR><BR>String of integer 3445 (radix 10): 3445<BR>String of integer 3445 (radix 16): 0xd75<BR>String of integer 3445 (radix 2): 110101110101<BR>String of long int -344115 (radix 16): 0xfffabfcd<BR>String of unsigned long 1234567890 (radix 16): 0x499602d2<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:凯凯 回复日期:2002-10-19 15:20:38
<br>内容:如果用MFC的话,就可以直接用CString类的Format函数。<BR>str.Format(_T("%d"), lValue);
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:小妮 回复日期:2002-10-19 21:52:26
<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 + -