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)

  

_itoa_s, _i64toa_s, _ui64toa_s, _itow_s, _i64tow_s, _ui64tow_s的更多相关文章

  1. itoa 和_itoa_s

    1> itoa, 将整数转换为字符串. char *  itoa ( int value, char * buffer, int radix ); 它包含三个参数: value, 是要转换的数字 ...

  2. _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明

    原文:http://www.cnblogs.com/lidabo/archive/2012/07/10/2584706.html _itoa 功能:把一整数转换为字符串 用法:char * _itoa ...

  3. MFC数据类型转换 _itoa atoi、atof、itoa、itow _itoa_s

    _itoa 功能:把一整数转换为字符串 用法:char * _itoa(int value, char *string, int radix); 详细解释: _itoa是英文integer to ar ...

  4. C++中 _itoa_s方法简介

    _itoa_s 函数原型如下: _itoa_s ( int value, char *buffer, size_t sizeInCharacters, //存放结果的字符数组长度 int radix ...

  5. C++ Unicode SBCS 函数对照表,以备日后查阅(很全)

    C++ Unicode SBCS 函数对照表,以备日后查阅 Generic SBCS UNICODE TCHAR char wchar_t _TEOF EOF WEOF _TINT int wint_ ...

  6. c语言_头文件_stdlib

    简介 stdlib 头文件即standard library标准库头文件 stdlib 头文件里包含了C.C++语言的最常用的系统函数 该文件包含了C语言标准库函数的定义 stdlib.h里面定义了五 ...

  7. C++ Unicode SBCS 函数对照表

    C++ Unicode SBCS 函数对照表,以备日后查阅 Generic SBCS UNICODE TCHAR char wchar_t _TEOF EOF WEOF _TINT int wint_ ...

  8. boost-字符文本处理

    1.lexical_cast 一些常见的数值,字符互转函数: 整型int: itoa()._itoa_s atoi()._ttoi 无符号整型unsigned int: _ultoa_s()._ult ...

  9. Golang 效率初(粗)测

    从接触 Golang 开始,断断续续已有差不多一年左右的时间了,都是业余自己学学看看,尚主要限于语法及语言特性,还没有用它写过实际的项目. 关于 Golang 的语法及语言特性,网上有很多资源可以学习 ...

随机推荐

  1. EM 算法

    这个暂时还不太明白,先写一点明白的. EM:最大期望算法,属于基于模型的聚类算法.是对似然函数的进一步应用. 我们知道,当我们想要估计某个分布的未知值,可以使用样本结果来进行似然估计,进而求最大似然估 ...

  2. HW2.18

    public class Solution { public static void main(String[] args) { System.out.println("a" + ...

  3. Linux文件误删除恢复操作

    作为一个多用户.多任务的操作系统,Linux下的文件一旦被删除,是难以恢复的.尽管删除命令只是在文件节点中作删除标记,并不真正清除文件内容,但是 其他用户和一些有写盘动作的进程会很快覆盖这些数据.不过 ...

  4. light oj 1155 - Power Transmission【拆点网络流】

    1155 - Power Transmission   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  5. AptanaStudio3 安装在win7 64bit时遇到的问题

    最近在研究前端语言,想起可以使用AptanaStudio这个前端利器,没想到安装时却遇到波折.先从网上下载了Aptana版本 3.6.0 64bit问题1 安装进度缓慢,第一次安装时,显示downlo ...

  6. UEFI引导修复教程和工具

    参考 http://bbs.wuyou.com/forum.php?mod=viewthread&tid=323759 1. MBR分区表:Master Boot Record,即硬盘主引导记 ...

  7. 牛一网ecshop家电数码模板(仿易迅网)for ecshop 2.7.3

            本模板尤其适用于家电数码行业. 本模板已经开发.测试完毕,并开放演示. 本模板支持全站静态.销售数量后台自定义.首页商品独立图片.品牌独立展示.商品精美团购.宽屏窄屏自动识别并切换.分 ...

  8. linux 查看并终止进程

    1,查看port被那个进程占用 比如: netstat -anp | grep 1160 ps:查看port1169被那个进程占用. 2.查找进程 比如 :ps -ef | grep 'tomcat' ...

  9. ubuntu 远程 ubuntu

    一:被远程端ubuntu配置 參考windows远程ubuntu这篇文章里面的ubuntu配置 二:远程端ubuntu配置 1:打开Remmina Remote Desktop Client软件,例如 ...

  10. 关机相关(shutdown,reboot)

    慣用的關機指令: shutdown 由於Linux的關機是那麼重要的工作,因此除了你是在主機前面以tty7圖形介面來登入系統時, 不論用什麼身份都能夠關機之外,若你是使用遠端管理工具(如透過piett ...