Converts an integer to a string. These are versions of _itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow with security enhancements as described in Security Features in the CRT.

 
errno_t _itoa_s(
int value,
char *buffer,
size_t sizeInCharacters,
int radix
);
errno_t _i64toa_s(
__int64 value,
char *buffer,
size_t sizeInCharacters,
int radix
);
errno_t _ui64toa_s(
unsigned _int64 value,
char *buffer,
size_t sizeInCharacters,
int radix
);
errno_t _itow_s(
int value,
wchar_t *buffer,
size_t sizeInCharacters,
int radix
);
errno_t _i64tow_s(
__int64 value,
wchar_t *buffer,
size_t sizeInCharacters,
int radix
);
errno_t _ui64tow_s(
unsigned __int64 value,
wchar_t *buffer,
size_t sizeInCharacters,
int radix
);
template <size_t size>
errno_t _itoa_s(
int value,
char (&buffer)[size],
int radix
); // C++ only
template <size_t size>
errno_t _itow_s(
int value,
wchar_t (&buffer)[size],
int radix
); // C++ only
[in] value

Number to be converted.

[out] buffer

Filled with the result of the conversion.

[in] sizeInCharacters

Size of the buffer in single-byte characters or wide characters.

[in] radix

Base of value; which must be in the range 2–36.

Zero if successful; an error code on failure. If any of the following conditions applies, the function invokes an invalid parameter handler, as described in Parameter Validation.

Error Conditions

value

buffer

sizeInCharacters

radix

Return

any

NULL

any

any

EINVAL

any

any

<=0

any

EINVAL

any

any

<= length of the result string required

any

EINVAL

any

any

any

radix < 2 or radix > 36

EINVAL

Security Issues

These functions can generate an access violation if buffer does not point to valid memory and is not NULL, or if the length of the buffer is not long enough to hold the result string.

Except for the parameters and return value, the _itoa_s functions have the same behavior as the corresponding less secure versions.

In C++, using these functions is simplified by template overloads; the overloads can infer buffer length automatically (eliminating the need to specify a size argument) and they can automatically replace older, non-secure functions with their newer, secure counterparts. For more information, see Secure Template Overloads.

The debug versions of these functions first fill the buffer with 0xFD. To disable this behavior, use _CrtSetDebugFillThreshold.

Generic-Text Routine Mappings

Tchar.h routine

_UNICODE and _MBCS not defined

_MBCS defined

_UNICODE defined

_itot_s

_itoa_s

_itoa_s

_itow_s

_i64tot_s

_i64toa_s

_i64toa_s

_i64tow_s

_ui64tot_s

_ui64toa_s

_ui64toa_s

_ui64tow_s

 
 
 
 
 
 
 
 

Routine

Required header

_itoa_s

<stdlib.h>

_i64toa_s

<stdlib.h>

_ui64toa_s

<stdlib.h>

_itow_s

<stdlib.h> or <wchar.h>

_i64tow_s

<stdlib.h> or <wchar.h>

_ui64tow_s

<stdlib.h> or <wchar.h>

For more compatibility information, see Compatibility in the Introduction.

 

// crt_itoa_s.c
#include <stdlib.h>
#include <string.h> int main( void )
{
char buffer[65];
int r;
for( r=10; r>=2; --r )
{
_itoa_s( -1, buffer, 65, r );
printf( "base %d: %s (%d chars)\n", r, buffer, strnlen(buffer, _countof(buffer)) );
}
printf( "\n" );
for( r=10; r>=2; --r )
{
_i64toa_s( -1L, buffer, 65, r );
printf( "base %d: %s (%d chars)\n", r, buffer, strnlen(buffer, _countof(buffer)) );
}
printf( "\n" );
for( r=10; r>=2; --r )
{
_ui64toa_s( 0xffffffffffffffffL, buffer, 65, r );
printf( "base %d: %s (%d chars)\n", r, buffer, strnlen(buffer, _countof(buffer)) );
}
}

  

 
 

base 10: -1 (2 chars)
base 9: 12068657453 (11 chars)
base 8: 37777777777 (11 chars)
base 7: 211301422353 (12 chars)
base 6: 1550104015503 (13 chars)
base 5: 32244002423140 (14 chars)
base 4: 3333333333333333 (16 chars)
base 3: 102002022201221111210 (21 chars)
base 2: 11111111111111111111111111111111 (32 chars) base 10: -1 (2 chars)
base 9: 145808576354216723756 (21 chars)
base 8: 1777777777777777777777 (22 chars)
base 7: 45012021522523134134601 (23 chars)
base 6: 3520522010102100444244423 (25 chars)
base 5: 2214220303114400424121122430 (28 chars)
base 4: 33333333333333333333333333333333 (32 chars)
base 3: 11112220022122120101211020120210210211220 (41 chars)
base 2: 1111111111111111111111111111111111111111111111111111111111111111 (64 chars) base 10: 18446744073709551615 (20 chars)
base 9: 145808576354216723756 (21 chars)
base 8: 1777777777777777777777 (22 chars)
base 7: 45012021522523134134601 (23 chars)
base 6: 3520522010102100444244423 (25 chars)
base 5: 2214220303114400424121122430 (28 chars)
base 4: 33333333333333333333333333333333 (32 chars)
base 3: 11112220022122120101211020120210210211220 (41 chars)
base 2: 1111111111111111111111111111111111111111111111111111111111111111 (64 chars)

  

最新文章

  1. 前端学HTTP之连接管理
  2. IOS开发 - TextField 控件详细
  3. python基础-基本数据类型总结_整型(int)_字符型(str)_day3
  4. IPC----哲学家就餐问题(并发与互斥)
  5. Java Hour4
  6. web安全 -- 常见攻击方法及预防措施
  7. C++的三种继承方式简述
  8. Quartz Scheduler(2.2.1) - Usage of CronTriggers
  9. jquery 移除数组重复的元素----$.unique()
  10. Bug :”解压压缩文件失败: cpio; 在头中不存在归档“
  11. php 多维数组 arrayList array()
  12. 24、手把手教你Extjs5(二十四)模块Form的自定义的设计[3]
  13. Android图表库MPAndroidChart(九)——神神秘秘的散点图
  14. Webpack3 从入门到放弃
  15. nodejs基础(三)
  16. iOS开发中@property的属性weak nonatomic strong readonly等
  17. String类的一些细节
  18. 新手学cocos2dx,centos7下的安装过程
  19. vue深入了解组件——处理边界情况
  20. JS的可枚举性

热门文章

  1. Web服务之LNMMP架构及动静分离实现
  2. 【hadoop2.6.0】数据丢失问题解决
  3. wf(三)
  4. 安装pgadmin3
  5. Android权限安全(3)权限的分级和自定义权限
  6. [杂题]FZU2190 非提的救赎
  7. elasticsearch,http://ip:9200访问不到的解决办法
  8. 《转载》详解 CSS 属性 - 伪类和伪元素的区别
  9. NSDate与时间戳的那点事
  10. Neo4j 第五篇:批量更新数据
  11. Linux文件的复制、删除和移动命令
  12. Core Graphics框架是Quartz的核心,也是内容描画的基本接口。
  13. &lt;script&gt;元素在XHTML中的用法
  14. 0417 jQuery基础知识
  15. Unity Graphics(一):选择一个光照系统
  16. Springboot多数据源配置--数据源动态切换
  17. eclipse集成tomcat日志文件输出配置
  18. 转:Spring与Mybatis整合的MapperScannerConfigurer处理过程源码分析
  19. SpringBoot鸡汤(注解集合二)
  20. 【原创】&lt;Debug&gt; “duplicate connection name”