C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Wert-Ausgabe einer char-Variablen mit cout

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
helmut
Guest





PostPosted: Sun Nov 16, 2003 9:01 am    Post subject: Wert-Ausgabe einer char-Variablen mit cout Reply with quote



Wie kann ich mit cout den Wert einer char-Variablen ausgeben

char c =97;

cout <<"c=" << c; //ergibt c=a, ich möchte aber c=97
//so geht es zwar, aber ...........
cout << "c=" << c +1 - 1;

Gruss

Helmut

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
Back to top
Markus Schaaf
Guest





PostPosted: Sun Nov 16, 2003 10:20 am    Post subject: Re: Wert-Ausgabe einer char-Variablen mit cout Reply with quote



"helmut" <helmut.weil (AT) t-online (DOT) de> schrieb:

Quote:
Wie kann ich mit cout den Wert einer char-Variablen ausgeben

//so geht es zwar, aber ...........
cout << "c=" << c +1 - 1;

Kürzer: c+0
Noch lürzer: +c
Nicht kürzer, aber verständlicher: int(c)

Der Effekt auf das Compilat ist immer der gleiche.

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Ulrich Schramme
Guest





PostPosted: Sun Nov 16, 2003 10:21 am    Post subject: Re: Wert-Ausgabe einer char-Variablen mit cout Reply with quote



helmut wrote:

Quote:
Wie kann ich mit cout den Wert einer char-Variablen ausgeben

char c =97;

cout <<"c=" << c; //ergibt c=a, ich möchte aber c=97
//so geht es zwar, aber ...........
cout << "c=" << c +1 - 1;

Gruss

Helmut


cout << "c = " << (int) a;
--
-- Ulli
www.u-schramme.de

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Ulrich Schramme
Guest





PostPosted: Sun Nov 16, 2003 10:25 am    Post subject: Re: Wert-Ausgabe einer char-Variablen mit cout Reply with quote

helmut wrote:

Quote:
Wie kann ich mit cout den Wert einer char-Variablen ausgeben

char c =97;

cout <<"c=" << c; //ergibt c=a, ich möchte aber c=97
//so geht es zwar, aber ...........
cout << "c=" << c +1 - 1;

Gruss

Helmut


cout << "c = " << (int) c;

Das (int) a im vorigen Posting war ein Tippfehler. Entschuldigung!
--
-- Ulli
www.u-schramme.de

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Andreas Brachold
Guest





PostPosted: Sun Nov 16, 2003 10:25 am    Post subject: Re: Wert-Ausgabe einer char-Variablen mit cout Reply with quote

Hallo,

Quote:
Wie kann ich mit cout den Wert einer char-Variablen ausgeben

char c =97;
cout <<"c=" << c; //ergibt c=a, ich möchte aber c=97 //so geht es
..

Ich weiss direkte cast sind verpönnt,
aber wie wäre es mit folgendem

cout <<"c=" << (int)c;


Andreas

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Jirka Klaue
Guest





PostPosted: Sun Nov 16, 2003 10:37 am    Post subject: Re: Wert-Ausgabe einer char-Variablen mit cout Reply with quote

helmut wrote:
Quote:
Wie kann ich mit cout den Wert einer char-Variablen ausgeben

char c =97;

cout <<"c=" << c; //ergibt c=a, ich möchte aber c=97
//so geht es zwar, aber ...........
cout << "c=" << c +1 - 1;

cout << c + 0; // Wink
cout << (int)c;

Jirka

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
helmut
Guest





PostPosted: Mon Nov 17, 2003 7:32 am    Post subject: Re: Wert-Ausgabe einer char-Variablen mit cout Reply with quote

Jirka Klaue <jklaue (AT) ee (DOT) tu-berlin.de> wrote

Quote:
helmut wrote:
Wie kann ich mit cout den Wert einer char-Variablen ausgeben

char c =97;

cout <<"c=" << c; //ergibt c=a, ich möchte aber c=97
//so geht es zwar, aber ...........
cout << "c=" << c +1 - 1;

cout << c + 0; // Wink
cout << (int)c;

Jirka
Vielen Dank an alle,


Helmut

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group