itoa 和_itoa_s
来源:互联网 发布:淘宝库存监控软件 编辑:程序博客网 时间:2024/06/14 03:18
itoa 和_itoa_s
1.itoa (将整数转换为字符串)
char * itoa ( int value, char * buffer, int radix );
它包含三个参数:
value, 是要转换的数字;
buffer, 是存放转换结果的字符串;
radix, 是转换所用的基数,2-36。如,2:二进制,10:十进制,16:十六进制
扩展:
ltoa() 将长整型值转换为字符串
ultoa() 将无符号长整型值转换为字符串
例子,将一个十进制数转化成二进制表示的字符串
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<queue>#include<vector>#include<cmath>#include<string>#define ll long long using namespace std;char s[32];int main(){ int n; while(cin>>n){ itoa(n,s,2); cout<<s<<endl; } return 0;}
2._itoa_s (是 itoa 的安全版本,除了参数和返回值不同,两个函数的行为是相同的,都是将整数转换为字符串)
errno_t _itoa_s(int value, char *buffer, size_t sizeInCharacters, int radix);
_itoa_s 比 itoa 多出一个参数:
value, 是要转换的数字;
buffer, 是存放转换结果的字符串;
sizeInCharacters, 存放转换结果的字符串长度
radix, 是转换所用的基数,2-36。如,2:二进制,10:十进制,16:十六进制、
Example
#include <stdio.h>#include <stdlib.h>#include <string.h>int _tmain(int argc, _TCHAR* argv[]){ 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)) ); } return 0;}
头文件:c中是 stdlib.h,c++中是cstdlib
0 0
- itoa 和_itoa_s
- itoa函数 和_itoa_s函数
- [C++]strcpy和strcpy_s itoa和_itoa_s
- C++中,int和char互转函数_itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明
- C/C++自带十进制转其它进制函数接口itoa/_itoa_s
- atoi和itoa函数
- 浅析atoi和itoa
- atoi 和itoa用法
- 手机App: Web App、Hybrid App、 Native App
- 模块化js编写模板
- JAVA初窥:Thread线程基础
- 设计模式系列·Facade模式之MVC的烦恼
- 蛇形填空3-3
- itoa 和_itoa_s
- Linux系统上的特殊权限
- ChatServer
- http 缓存机制
- linux和win10双系统手动或开机自动挂载磁盘
- 投资计划以及小结
- 开发小游戏之(案例——装备选择)
- C#特性详解
- L1-039. 古风排版(2017初赛)