📄 subject_18305.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 <stdlib.h> Win 95, Win NT <BR>_ltow <stdlib.h> 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 _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 <stdlib.h><BR>#include <stdio.h><BR><BR>void main( void )<BR>{<BR> char buffer[20];<BR> int i = 3445;<BR> long l = -344115L;<BR> unsigned long ul = 1234567890UL;<BR><BR> _itoa( i, buffer, 10 );<BR> printf( "String of integer %d (radix 10): %s\n", i, buffer );<BR> _itoa( i, buffer, 16 );<BR> printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );<BR> _itoa( i, buffer, 2 );<BR> printf( "String of integer %d (radix 2): %s\n", i, buffer );<BR><BR> _ltoa( l, buffer, 16 );<BR> printf( "String of long int %ld (radix 16): 0x%s\n", l, <BR> buffer );<BR><BR> _ultoa( ul, buffer, 16 );<BR> printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,<BR> 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 + -