Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Simple IO input a char using tango

Moderators: larsivi kris

Posted: 02/11/08 13:13:58 Modified: 02/11/08 13:30:36

Dear sirs,

Although I am a newbie to Tango,I am loving D...

Here is just a very simple problem I met :How to (using Tango of course!) input a char to console ,say 'a' and then output this char.Which function should I use? All I have found is with char[],not a single char,for example,Cin.get() returns a char[],right?Is there any equivelent way as in C++:

char input;//here just char,not char[];

cin>>input;//say input a 'a';

cout<<"you have entered "<<input<<endl;//this will output letter 'a';

also it is an additional question that how to ouput 97 other than 'a';

Please help.

Thanks a million.

Regards, Sam

Author Message

Posted: 02/11/08 14:09:41

Getting single characters isn't possible without wrapping some sort of event system, or using the C function getch. Since we're not using the console functionality of the C stdlib were getch is present, we'd rather not have to depend on it for this particular case.

However, if it could be implemented in a not-to-hairy way, that also fits in with the rest of Tango's IO in some fashion, we could consider it.

As for your additional question, do you mean that you want to print the index of the letter from the ascii table? As long as the letter actually is part of the ascii table, you can do

cast(int)c;