Share via


_atoi64、_atoi64_l、_wtoi64、_wtoi64_l

更新 : 2007 年 11 月

文字列を 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 型の値を返します。入力値をその型の値に変換できない場合、_atoi64 の戻り値は 0 です。

Visual C++ 2005 で正の大きな整数値によるオーバーフローが発生した場合、_atoi64 は I64_MAX を返し、負の大きな整数値によるオーバーフローの場合は I64_MIN を返します。

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

解説

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

入力文字列は、指定された型の数値として解釈できる文字の並びにします。関数は、入力文字列の読み込み時に、数値の一部として認識できない文字が現れた時点で停止します。この文字は、文字列の終わりを示す null 文字 ('\0' または L'\0') の場合もあります。

_atoi64 の str 引数は、次の形式です。

[whitespace] [sign] [digits]]

whitespace はスペースやタブで構成され、無視されます。sign は正符号 (+) または負符号 (–) のいずれかで、digits は 1 つ以上の 10 進数字です。

_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");
    }
}

Function: _atoi64( "  -2309 " ) = -2309
Function: _atoi64( "314127.64" ) = 314127
Function: _atoi64( "3336402735171707160320" ) = -1
Overflow condition occurred.

.NET Framework の相当するアイテム

参照

参照

データ変換

浮動小数点サポート

ロケール

_ecvt

_fcvt

_gcvt

setlocale、_wsetlocale

_atodbl、_atodbl_l、_atoldbl、_atoldbl_l、_atoflt _atoflt_l