字符串与数值相互转换的函数
2010-12-11 15:42
411 查看
字符串与数值相互转换的函数
atoi、atof、itoa、itow函数是windows平台下实现字符串与数值相互转换的函数【参考】
atoi函数
原型:int atoi( const char *string );
ASCII to integer
作用:将字符串转为integer类型
atof函数
原型:double atof( const char *string );
ASCII to float
作用:将字符串转为double类型
_itoa函数
原型:char *_itoa( int value, char *str, int radix );//2<=radix<=36
Integer to ASCII
作用:将Integer类型转换为radix进制,然后以ASCII字符串的形式存放在str中
_itow函数
wchar_t * _itow( int value, wchar_t *str, int radix ); //2<=radix<=36
Integer to Wide Char
作用:将Integer类型转换为radix进制,然后以宽字符串的形式存放在str中
atol等省略。
自从VS2005版本以后,都有了更加严格的转换函数了, 如itoa > _itoa > _itoa_s(推荐)
_gcvt_s
Converts a floating-point value to a string. This is a version of _gcvt with security enhancements as described in Security Features in the CRT.
[/code]
atoi、atof、itoa、itow函数是windows平台下实现字符串与数值相互转换的函数【参考】
atoi函数
原型:int atoi( const char *string );
ASCII to integer
作用:将字符串转为integer类型
atof函数
原型:double atof( const char *string );
ASCII to float
作用:将字符串转为double类型
_itoa函数
原型:char *_itoa( int value, char *str, int radix );//2<=radix<=36
Integer to ASCII
作用:将Integer类型转换为radix进制,然后以ASCII字符串的形式存放在str中
_itow函数
wchar_t * _itow( int value, wchar_t *str, int radix ); //2<=radix<=36
Integer to Wide Char
作用:将Integer类型转换为radix进制,然后以宽字符串的形式存放在str中
atol等省略。
自从VS2005版本以后,都有了更加严格的转换函数了, 如itoa > _itoa > _itoa_s(推荐)
_gcvt_s
Converts a floating-point value to a string. This is a version of _gcvt with security enhancements as described in Security Features in the CRT.
errno_t _gcvt_s( char *buffer, size_t sizeInBytes, double value, int digits ); template <size_t cchStr> errno_t _gcvt_s( char (&buffer)[cchStr], double value, int digits ); // C++ only
sample:
[code]// crt_gcvt_s.c #include <stdio.h> #include <stdlib.h> #include <errno.h> int main() { char buf[_CVTBUFSIZE]; int decimal; int sign; int err; err = _gcvt_s(buf, _CVTBUFSIZE, 1.2, 5); if (err != 0) { printf("_gcvt_s failed with error code %d/n", err); exit(1); } printf("Converted value: %s/n", buf); }
[/code]
相关文章推荐
- 字符串与数值相互转换的函数
- java 数值类型和字符串的相互转换
- 【web开发 js数据转换】javascript数值与字符串的相互转换
- 字符串转换数值函数:_tcstoul()与_tcstol()的区别!
- JavaScript数值与字符串类型转换的三种函数
- C++数值与字符串相互转换的那些事(一)字符串转数值(转载请注明)
- 数值和字符串相互转换(C++ 数据类型转换技巧)
- json格式字符串与json对象相互转换的函数
- c++中字符串与数值的相互转换
- C#:数值与字符串之间相互转换
- C#中字符串与数值的相互转换
- 字符串IP地址转换成IP数值函数
- postgreSQL数据类型字符串和数值相互转换
- C/C++中字符串与数值相互转换
- c++11 数值类型和字符串的相互转换
- 字符串之间相互转换 字符与数值之间的转换
- cocos2d JS-(JavaScript) 函数类型相互转换(字符串、整形、浮点形、布尔值)
- sscanf进行字符串分离、提取。以及string与数值的相互转换
- 字符串和数值的相互转换【java】
- C# 八进制数值字符串转换成ASCII 字符串相互转换