_atoi64、 _atoi64_l、 _wtoi64、 _wtoi64_l

將字串轉換為 64 位元的整數。

__int64 _atoi64(
   const char *str 
);
__int64 _wtoi64(
   const wchar_t *str 
);
__int64 _atoi64_l(
   const char *str,
   _locale_t locale
);
__int64 _wtoi64_l(
   const wchar_t *str,
   _locale_t locale
);

參數

  • str
    以指定須轉換的字串。

  • locale
    若要使用的地區設定。

傳回值

每個函式會傳回__int64值所產生的解譯為數字的輸入的字元。傳回值是 0, _atoi64如果輸入無法轉換成該型別的值。

具有較大的正數、 整數值,溢位的情況下**_atoi64**會傳回I64_MAX和I64_MIN大負數的整數類資料值溢位的情況下。

在所有範圍外的情況下, errno設定為 [ ERANGE。如果傳入的參數是NULL,不正確的參數處理常式會叫用,如所述參數驗證。如果執行,則允許繼續執行,這些函式會設定errno到EINVAL ,並傳回 0。

備註

這些函式會將字元字串轉換為 64 位元整數值。

輸入的字串是一連串的字元會解譯為指定之型別的數值。此函式會停止讀取輸入無法辨識的數字的組件的第一個字元字串。這個字元可能是 null 字元 ('\ 0' 或 '\ 0' L) 結束的字串。

str引數為**_atoi64**都採用下列格式:

[whitespace] [sign] [digits]]

A whitespace包含空格或 tab 字元,會被忽略 ; sign可能是加號 (+) 或減號 (-) ; 與digits是一或多個位數字。

_wtoi64是相同的**_atoi64**不同之處在於它採用寬字元字串做為參數。

使用這些函式的版本_l尾碼完全相同,不同之處在於它們使用傳遞中而不是目前的地區設定的地區設定參數。如需詳細資訊,請參閱 地區設定

泛用文字常式對應

Tchar.h 常式

_Unicode 之後,未定義的 _MBCS

定義的 _MBCS

定義 _unicode 之後

_tstoi64

_atoi64

_atoi64

_wtoi64

_ttoi64

_atoi64

_atoi64

_wtoi64

需求

常式

所需的標頭

_atoi64, _atoi64_l

<stdlib.h>

_wtoi64, _wtoi64_l

<stdlib.h> 或者 <wchar.h>

範例

此程式會示範如何轉換儲存為字串的數字,值必須為數字使用**_atoi64**函式。

// crt_atoi64.c
// This program shows how numbers stored as
// strings can be converted to numeric values
// using the _atoi64 functions.
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int main( void )
{
    char    *str = NULL;
    __int64 value = 0;

    // An example of the _atoi64 function
    // with leading and trailing white spaces.
    str = "  -2309 ";
    value = _atoi64( str );
    printf( "Function: _atoi64( \"%s\" ) = %d\n", str, value );

    // Another example of the _atoi64 function 
    // with an arbitrary decimal point.
    str = "314127.64";
    value = _atoi64( str );
    printf( "Function: _atoi64( \"%s\" ) = %d\n", str, value );

    // Another example of the _atoi64 function
    // with an overflow condition occurring.
    str = "3336402735171707160320";
    value = _atoi64( str );
    printf( "Function: _atoi64( \"%s\" ) = %d\n", str, value );
    if (errno == ERANGE)
    {
       printf("Overflow condition occurred.\n");
    }
}
  

.NET Framework 對等用法

請參閱

參考

資料轉換

浮點支援

地區設定

_ecvt

_fcvt

_gcvt

setlocale _wsetlocale

_atodbl、 _atodbl_l、 _atoldbl、 _atoldbl_l、 _atoflt _atoflt_l