_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

範囲外のすべての場合、errnoERANGE に設定されます。 渡されたパラメーターが指定されている場合、「NULLパラメーターの検証」で説明されているように、無効なパラメーター ハンドラーが呼び出されます。 実行の継続が許可された場合、これらの関数は errnoEINVAL に設定し、0 を返します。

解説

これらの関数は、文字列を 64 ビット整数値に変換します。

入力文字列は、指定された型の数値として解釈できる文字シーケンスです。 この関数は、数値の一部として認識できない最初の文字で入力文字列の読み取りを停止します。 この文字は、文字列を終了する null 文字 ('\0' または L'\0') である場合があります。

str_atoi64 引数には、次の形式があります。

[whitespace] [sign] [digits]

whitespace はスペースまたはタブで構成され、無視されます。sign はプラス (+) またはマイナス (-) のいずれかで、digits は 1 つ以上の数字です。

_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