Click here to Skip to main content
15,896,915 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Run-Time Check Failure #2 Pin
Bob Stanneveld7-Jul-05 5:45
Bob Stanneveld7-Jul-05 5:45 
Questionhow to uninstall U disk Pin
6-Jul-05 18:35
suss6-Jul-05 18:35 
AnswerRe: how to uninstall U disk Pin
David Crow7-Jul-05 5:07
David Crow7-Jul-05 5:07 
Generalswitch() function Pin
Anonymous6-Jul-05 18:35
Anonymous6-Jul-05 18:35 
GeneralRe: switch() function Pin
khan++6-Jul-05 19:22
khan++6-Jul-05 19:22 
GeneralRe: switch() function Pin
Bob Stanneveld6-Jul-05 20:44
Bob Stanneveld6-Jul-05 20:44 
GeneralRe: switch() function Pin
Anonymous7-Jul-05 8:18
Anonymous7-Jul-05 8:18 
GeneralRe: switch() function Pin
Bob Stanneveld7-Jul-05 19:51
Bob Stanneveld7-Jul-05 19:51 
Anonymous wrote:
ForumVisual C++
Subject:Re: switch() function
Sender:Anonymous
Date:14:18 7 Jul '05

Don't think you read the question right. The default works fine if an interger is entered (any number) but if a character is enter, it won't work!!!!!


I don't think that you can program very well. That's OK since we are here to help.

I read the question and I can assure you that I understand it perfectly well! Your problem is that you don't know what you are doing. Let me elaborate: characters (I'll stick to single byte characters for simplicity) are represented by integral values in the range 0x0 to 0xFF. Integers (the usual 32bit integers) have values in the range 0x0 to 0xFFFFFFFF. What did we learn from this is that you can store an character into an int without problems. So a simple static_cast will solve your problem.

If you work with the datatype char however, the following code will do the trick:
std::cin >> cYourChar;
switch( cYourChar )
{
case '0': { /* code */ break; } // a 0 is entered
case '1': { /* code */ break; } // a 1 is entered
case '2': { /* code */ break; } // ...
case '3': { /* code */ break; }
case '4': { /* code */ break; }
case '5': { /* code */ break; }
case '6': { /* code */ break; }
case '7': { /* code */ break; }
case '8': { /* code */ break; }
case '9': { /* code */ break; }
default:
 // other character
}



Behind every great black man...
            ... is the police. - Conspiracy brother


Blog[^]
GeneralRe: switch() function Pin
Maximilien7-Jul-05 0:38
Maximilien7-Jul-05 0:38 
Questionhow to use mfc in win32 dll? Pin
gohappy_19996-Jul-05 18:05
gohappy_19996-Jul-05 18:05 
AnswerRe: how to use mfc in win32 dll? Pin
ThatsAlok6-Jul-05 20:23
ThatsAlok6-Jul-05 20:23 
GeneralVARIANT/COM Hell Pin
Christian Graus6-Jul-05 17:03
protectorChristian Graus6-Jul-05 17:03 
GeneralRe: VARIANT/COM Hell Pin
Jose Lamas Rios7-Jul-05 7:46
Jose Lamas Rios7-Jul-05 7:46 
GeneralRe: VARIANT/COM Hell Pin
Christian Graus7-Jul-05 13:15
protectorChristian Graus7-Jul-05 13:15 
GeneralRe: VARIANT/COM Hell Pin
Jose Lamas Rios7-Jul-05 15:49
Jose Lamas Rios7-Jul-05 15:49 
GeneralHowe to insert a number into a table in the Oracle by ADO Pin
zwzcode6-Jul-05 15:22
zwzcode6-Jul-05 15:22 
GeneralHELP problem with CComboBox AddString recovery Pin
cgb1436-Jul-05 14:06
cgb1436-Jul-05 14:06 
GeneralRe: HELP problem with CComboBox AddString recovery Pin
Christian Graus6-Jul-05 14:44
protectorChristian Graus6-Jul-05 14:44 
GeneralRe: HELP problem with CComboBox AddString recovery Pin
cgb1436-Jul-05 15:13
cgb1436-Jul-05 15:13 
GeneralRe: HELP problem with CComboBox AddString recovery Pin
Brad Bruce6-Jul-05 14:59
Brad Bruce6-Jul-05 14:59 
GeneralRe: HELP problem with CComboBox AddString recovery Pin
cgb1437-Jul-05 5:28
cgb1437-Jul-05 5:28 
GeneralRe: HELP problem with CComboBox AddString recovery Pin
David Crow6-Jul-05 15:44
David Crow6-Jul-05 15:44 
GeneralRe: HELP CComboBox AddString and recovery Pin
Anonymous6-Jul-05 13:54
Anonymous6-Jul-05 13:54 
Generalconvert number to char Pin
Ista6-Jul-05 12:42
Ista6-Jul-05 12:42 
GeneralRe: convert number to char Pin
markkuk6-Jul-05 13:06
markkuk6-Jul-05 13:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.