Stupid Question : wchar_t to Int

M

Mark Prenter

Hi, I think I've got a really dumb question here: I started off with a
String* containing the string "03452". I took this value and converted it
to a __gc[] wchar_t array using ->ToCharArray(). So far so good. Now I've
got an array of single digits. This is what I want.

The first wchar_t array element now contains "0", the first character of my
original string. What I now want to do is convert this to an INT. So
instead of a char "0", it's an INT 0. I can't seem to figure out how to do
this. The closest I get is 48, which is the ASCII value of the char "0".
Please help. I've pulled out so much hair I've hardly got any left. How
can I do this?

Thanks,
/\/\ark
 
W

William DePalo [MVP VC++ ]

Mark Prenter said:
What I now want to do is convert this to an INT. So
instead of a char "0", it's an INT 0. I can't seem to figure out how to do
this. The closest I get is 48, which is the ASCII value of the char "0".
Please help. I've pulled out so much hair I've hardly got any left. How
can I do this?

Make sure that the character value is greater than or equal to '0' and less
than or equal to '9' then subtract '0'.

Regards,
Will
 
M

Mark Prenter

Cool!!

Thanks,
/\/\ark

P.S. - I also noticed that I should have been using an __wchar_t....not a
wchar_t.
 
B

Brandon Bray [MSFT]

Mark said:
P.S. - I also noticed that I should have been using an __wchar_t....not a
wchar_t.

You can also compile with the /Zc:wchar_t compiler switch. wchar_t is a real
type according to the C++ standard. Visual C++ by default makes wchar_t a
typedef for an unsigned short. This switch directs the compiler to use the
standard conforming behavior.

Cheerio!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top