Skip to main content
GameDev.net gamedev.net
🔒 Locked

Trouble converting ascii int into char?C++

Started by GameDev.net Jul 30, 2010 at 9:09 PM 8 replies 2.4k views
Original Post
GameDev.net
GameDev.net
I have written a small fragment and when it displays it keeps displaying the integer not the char value. Help pleeease:D
int ascValue=wParam;
char key=((char)ascValue);
MsgBox(key.ToString());


SiCrane
SiCrane
In C++, primitives don't have member functions. What language are you actually using?
SiCrane
SiCrane
Using an API doesn't change fundamental characteristics of a language like whether or not primitives have member functions.
Nypyren
Nypyren
Use 'Char', not 'char'.

'Char' is the .Net character type.
'char' is the C++ signed 8-bit integer type (sbyte in C#) which is why .ToString is printing it in numeric form.

By the way, you are using C++/CLI, not C++.

You might want to switch to C#. C++/CLI is probably the most confusing programming language in existence.

This code prints "d":

int main(array<System::String ^> ^args){	Char c = (Char)100;	String ^s = c.ToString();	Console::WriteLine(s);	return 0;}



This code prints "100":

int main(array<System::String ^> ^args){	char c = (char)100;	String ^s = c.ToString();	Console::WriteLine(s);	return 0;}



This is one reason why using C++/CLI can be a brainfuck.
SiCrane
SiCrane
Quote:
Original post by harminal
Well i think this question is irrelevant all i want to know is why i cannot convert my integer to char>.>


You think knowing which programming language a question concerns is irrelevant to answering the question? That just might be the stupidest thing I've ever heard here.
Zakwayda
Zakwayda
Quote:
Its irrelevant because i kept telling you its C++... And anyway the guy above me solved my answer! Thank you guy above me. No thanks to you sicrane....
You were asked what language you were using, and you answered incorrectly. It's not C++, but rather C++/CLI (which is very different).

To be fair, you're not the first beginning programmer to be thrown by the whole C++/CLI thing. However, the questions that were asked of you were completely reasonable, so there's no need to be snippy :|
Zahlman
Zahlman
Honestly, there are very, very few people in the world who have a good reason to be using the language you're using, and every single one of them would not stumble on this question. It is a very special-purpose thing.

If you want to have access to things like ToString(), use C# and get a C# book.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.