atoll, _atoll_l, _wtoll, _wtoll_l

文字列を long long 整数に変換します。

構文

long long atoll(
   const char *str
);
long long _wtoll(
   const wchar_t *str
);
long long _atoll_l(
   const char *str,
   _locale_t locale
);
long long _wtoll_l(
   const wchar_t *str,
   _locale_t locale
);

パラメーター

str
変換対象の文字列。

locale
使用するロケール。

戻り値

各関数は、入力文字を数字として解釈して生成される long long 値を返します。 入力をその型の atoll 値に変換できない場合、戻り値は 0 です。

より大きい正の整数値によるオーバーフローの場合、atollLLONG_MAX を返し、より大きい負の整数値によるオーバーフローの場合は LLONG_MIN を返します。

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

解説

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

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

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

[whitespace] [sign] [digits]

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

_wtoll は、ワイド文字列をパラメーターとして受け取る点を除いて atoll と同じです。

これらの関数のうち _l サフィックスが付けられたバージョンは、現在のロケールの代わりに渡されたロケール パラメーターを使用する点を除いて、サフィックスが付かないバージョンと同じです。 詳細については、「 Locale」を参照してください。

既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT のグローバル状態」を参照してください

汎用テキスト ルーチンのマップ

Tchar.h のルーチン _UNICODE_MBCS が定義されていない _MBCS が定義されている _UNICODE が定義されている
_tstoll atoll atoll _wtoll
_tstoll_l _atoll_l _atoll_l _wtoll_l
_ttoll _atoll _atoll _wtoll

必要条件

ルーチン 必須ヘッダー
atoll, _atoll_l <stdlib.h>
_wtoll, _wtoll_l <stdlib.h> または <wchar.h>

このプログラムは、atoll 関数を使用して、文字列として格納されている数字を数値に変換する方法を示します。

// crt_atoll.c
// Build with: cl /W4 /Tc crt_atoll.c
// This program shows how to use the atoll
// functions to convert numbers stored as
// strings to numeric values.
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

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

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

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

    // Another example of the atoll function
    // with an overflow condition occurring.
    str = "3336402735171707160320";
    value = atoll(str);
    printf("Function: atoll(\"%s\") = %lld\n", str, value);
    if (errno == ERANGE)
    {
       printf("Overflow condition occurred.\n");
    }
}
Function: atoll("  -27182818284 ") = -27182818284
Function: atoll("314127.64") = 314127
Function: atoll("3336402735171707160320") = 9223372036854775807
Overflow condition occurred.

関連項目

データ変換
数学と浮動小数点のサポート
ロケール
_ecvt
_fcvt
_gcvt
setlocale, _wsetlocale
_atodbl, _atodbl_l, _atoldbl, _atoldbl_l, _atoflt, _atoflt_l