我喜欢蓝天,也喜欢雨天。
分类: C/C++
2013-12-10 13:12:48
const char *str ); int _wtoi( const wchar_t *str );
包含头文件:#include <stdlib.h>
函数参数:str:要转换的字符串。
函数返回值:成功返回转换后的数值,失败返回0.超过最大值返回LONG_MAX,小于最小值返回LONG_MIN.
示例程序:
#include "stdafx.h" #include#include int _tmain(int argc, _TCHAR* argv[]) { char *str = NULL; wchar_t *wstr = NULL; int value = 0; // An example of the atoi function. str = " -3536 "; value = atoi( str ); printf( "Function: atoi( \"%s\" ) = %d\n", str, value ); // Another example of the atoi function. str = "41412765"; value = atoi( str ); printf( "Function: atoi( \"%s\" ) = %d\n", str, value ); // Another example of the atoi function // with an overflow condition occuring. str = "5556402735171707160320"; value = atoi( str ); printf( "Function: atoi( \"%s\" ) = %d\n", str, value ); if (errno == ERANGE) { printf("Overflow condition occurred.\n"); } ////////////////////////////////////////// wstr = L" -36309 "; value = _wtoi( wstr ); printf( "Function: _wtoi( \"%ws\" ) = %d\n", wstr, value ); // Another example of the _wtoi function. wstr = L"124544667"; value = _wtoi( wstr ); printf( "Function: _wtoi( \"%ws\" ) = %d\n", wstr, value ); // Another example of the _wtoi function // with an overflow condition occuring. wstr = L"548556564171707160320"; value = _wtoi( wstr ); printf( "Function: _wtoi( \"%ws\" ) = %d\n", wstr, value ); if (errno == ERANGE) { printf("Overflow condition occurred.\n"); } getchar(); return 0; } 运行结果:
另外,字符串转长整型介绍:http://blog.chinaunix.net/uid-29121609-id-4030955.html
字符串转换为double型:http://blog.chinaunix.net/uid-29121609-id-4031108.html