What's the best way to convert std::wstring to numeric type, such as int, long, float or double?
C++0x introduces the following functions in <string>
:
int stoi (const wstring& str, size_t* idx = 0, int base = 10);
long stol (const wstring& str, size_t* idx = 0, int base = 10);
unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
float stof (const wstring& str, size_t* idx = 0);
double stod (const wstring& str, size_t* idx = 0);
long double stold(const wstring& str, size_t* idx = 0);
idx
is an optionally null pointer to the end of the conversion within str
(set by the conversion function).