wcstof, wcstod, wcstold
來自 cppreference.com
在標頭檔案 <wchar.h> 中定義 |
||
float wcstof( const wchar_t* restrict str, wchar_t** restrict str_end ); |
(C99 起) | |
double wcstod( const wchar_t* str, wchar_t** str_end ); |
(自 C95 起) (直到 C99) |
|
double wcstod( const wchar_t* restrict str, wchar_t** restrict str_end ); |
(C99 起) | |
long double wcstold( const wchar_t* restrict str, wchar_t** restrict str_end ); |
(C99 起) | |
解釋 str 指向的寬字串中的浮點值。
函式會丟棄任何空白字元(由 iswspace 確定),直到找到第一個非空白字元。然後,它儘可能多地獲取字元以形成有效的浮點表示,並將其轉換為浮點值。有效的浮點值可以是以下之一:
- 十進位制浮點表示式。它由以下部分組成:
- (可選) 加號或減號
- 非空十進位制數字序列,可選地包含小數點字元(由當前的 C locale 確定)(定義有效數字)
- (可選)
e
或E
,後跟可選的減號或加號以及非空十進位制數字序列(定義以 10 為底的指數)
|
(C99 起) |
- 當前安裝的 C locale 可能接受的任何其他表示式。
函式將 str_end 指向的指標設定為指向解釋的最後一個字元之後的寬字元。如果 str_end 是空指標,則忽略它。
目錄 |
[編輯] 引數
str | - | 指向要解釋的以 null 結尾的寬字串的指標 |
str_end | - | 指向寬字元的指標的指標。 |
[編輯] 返回值
成功時,返回對應於 str 內容的浮點值。如果轉換後的值超出相應返回型別的範圍,則發生範圍錯誤並返回 HUGE_VAL、HUGE_VALF 或 HUGE_VALL。如果無法執行轉換,則返回 0。
[編輯] 示例
執行此程式碼
#include <errno.h> #include <stdio.h> #include <wchar.h> int main(void) { const wchar_t* p = L"111.11 -2.22 0X1.BC70A3D70A3D7P+6 1.18973e+4932zzz"; printf("Parsing L\"%ls\":\n", p); wchar_t* end; for (double f = wcstod(p, &end); p != end; f = wcstod(p, &end)) { printf("'%.*ls' -> ", (int)(end-p), p); p = end; if (errno == ERANGE){ printf("range error, got "); errno = 0; } printf("%f\n", f); } }
輸出
Parsing L"111.11 -2.22 0X1.BC70A3D70A3D7P+6 1.18973e+4932zzz": '111.11' -> 111.110000 ' -2.22' -> -2.220000 ' 0X1.BC70A3D70A3D7P+6' -> 111.110000 ' 1.18973e+4932' -> range error, got inf
[編輯] 參考
- C23 標準 (ISO/IEC 9899:2024)
- 7.29.4.1.1 wcstod、wcstof 和 wcstold 函式 (p: TBD)
- C17 標準 (ISO/IEC 9899:2018)
- 7.29.4.1.1 wcstod、wcstof 和 wcstold 函式 (p: TBD)
- C11 標準 (ISO/IEC 9899:2011)
- 7.29.4.1.1 wcstod、wcstof 和 wcstold 函式 (p: 426-428)
- C99 標準 (ISO/IEC 9899:1999)
- 7.24.4.1.1 wcstod、wcstof 和 wcstold 函式 (p: 372-374)
[編輯] 另請參閱
(C99)(C99) |
將位元組字串轉換為浮點值 (function) |
C++ 文件,關於 wcstof, wcstod, wcstold
|