Conversion of core::stringw / wchar_t* into f32 and s32

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Conversion of core::stringw / wchar_t* into f32 and s32

Post by smso »

Conversion of core::stringw / wchar_t* into f32 and s32 in linux,
without using std::istrstream:

Code: Select all

inline f32 wcharTof32(const wchar_t* wc) { return (f32)wcstod(wc, L'\0'); }
inline s32 wcharTos32(const wchar_t* wc) { return wcstol(wc, '\0', 10); }
Extracted from src of lightfeather
http://lightfeather.de/news.php


Regards
smso
Last edited by smso on Sat May 19, 2012 2:53 am, edited 1 time in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Conversion of core::stringw / wchar_t* into f32 and s32

Post by hendu »

Why use wcstod and then cast to float? There's a float function too ;)
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Conversion of core::stringw / wchar_t* into f32 and s32

Post by smso »

hendu wrote:Why use wcstod and then cast to float? There's a float function too ;)
hendu, you are right:

updated:

Code: Select all

inline f32 wcharTof32(const wchar_t* wc) { return wcstof(wc, L'\0'); }
inline s32 wcharTos32(const wchar_t* wc) { return wcstol(wc, '\0', 10); }
Thanks for the info. These functions are needed when I tried to make irrai and irrai editor compile with the svn version of irrlicht in linux.

Regards
smso
Post Reply