函式
<cwchar>

wcstof

float wcstof (const wchar_t* str, wchar_t** endptr);
將寬字串轉換為浮點數
解析 C 寬字串 str,將其內容解釋為浮點數,並以float型別返回其值。如果 endptr 不是空指標,則該函式還會將 endptr 的值設定為指向數字後面的第一個字元。

這是 strtof (<cstdlib>) 的寬字元等效版本,以相同的方式解釋 str

引數

str
以浮點數表示形式開頭的 C 寬字串。
endptr
對一個已分配的wchar_t*型別物件的引用,其值由函式設定為 str 中數值之後的下一個字元。
此引數也可以是空指標,在這種情況下,函式不使用它。

返回值

成功時,函式返回轉換後的浮點數,型別為float.
如果無法執行有效的轉換,則函式返回零(0.0F).
)。如果正確的值超出了該型別可表示值的範圍,則返回一個正或負的 HUGE_VALF,並將 errno 設定為 ERANGE
如果正確的值會導致下溢,則函式返回一個其絕對值不大於最小規格化正數的值(某些庫實現在這種情況下也可能將 errno 設定為 ERANGE)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
/* wcstof example */
#include <wchar.h>

int main ()
{
  wchar_t szOrbits[] = L"686.97 365.24";
  wchar_t * pEnd;
  double d1, d2;
  d1 = wcstof (szOrbits,&pEnd);
  d2 = wcstof (pEnd,NULL);
  wprintf (L"One martian year takes %.2f Earth years.\n", d1/d2);
  return 0;
}

輸出
One martian year takes 1.88 Earth years.


另見