Share via


_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

如果函式溢位具有大正整數值,則會傳回 I64_MAX 。 如果函式溢位具有大負整數值,則傳回 I64_MIN

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

備註

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

輸入字串是一串字元,可解譯為所指定類型的數值。 函式會在無法辨識為數字一部分的第一個字元停止讀取輸入字串。 此字元可能是終止字串的 Null 字元 ('\0' 或 L'\0')。

_atoi64str 引數具有下列形式:

[whitespace] [sign] [digits]

whitespace包含會忽略的空間或定位字元; sign 是加號(+)或減號(-),而且 digits 是一或多個數位。

_wtoi64_atoi64 相同,差別在於它採用寬字元字串作為參數。

這些有 _l 尾碼的函式版本是一樣的,不同之處在於會使用傳入的地區設定參數,而不使用目前的地區設定。 如需詳細資訊,請參閱 Locale

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

泛型文字常式對應

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");
    }
}
Function: _atoi64( "  -2309 " ) = -2309
Function: _atoi64( "314127.64" ) = 314127
Function: _atoi64( "3336402735171707160320" ) = -1
Overflow condition occurred.

另請參閱

資料轉換
數學和浮點支援
地區設定
_ecvt
_fcvt
_gcvt
setlocale, _wsetlocale
_atodbl, _atodbl_l, _atoldbl, _atoldbl_l, _atoflt, _atoflt_l