473,547 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[c++] getting the ASCII value of a char

Hello folks,

I just started a C++ course. An exercise is to give the ASCII value of
a character read from keyboard. I place the input from the keyboard in
a char-variable. How can i get the ASCII value of this char? Is there
a built-in function? Or should i check the full table?

Thanks.
Jasper
Jul 23 '05 #1
6 8695
This is it...
-#include <iostream>
-
-int main()
-{
- char a;
- std::cin >> a;
- std::cout << a << " " << int(a) << std::endl;-

- return 0;
-}

Jul 23 '05 #2
Haas wrote:
Hello folks,

I just started a C++ course. An exercise is to give the ASCII value of
a character read from keyboard.
I assume your implementation uses ASCII or something based on that as a
character set? C++ doesn't define the character set to be used.
I place the input from the keyboard in a char-variable. How can i get the
ASCII value of this char?
It already has that value. char is nothing else than a small integer.
Is there a built-in function?
No such function needed.
Or should i check the full table?


Not needed if your system uses an ASCII character set.

Jul 23 '05 #3
Haas wrote:
Hello folks,

I just started a C++ course. An exercise is to give the ASCII value of
a character read from keyboard. I place the input from the keyboard in
a char-variable. How can i get the ASCII value of this char? Is there
a built-in function? Or should i check the full table?

char c;

int i= c;

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #4
char c= 'a';

int i= c;
--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5
Ioannis Vranos wrote:
char c= 'a';

int i= c;


You don't need to do this, unless there is an overwhelming
desire to have the value as a signed int. char is merely
a (usually) smaller int.

--
Jonathan Arnold (mailto:jd***** *@buddydog.org)
The Incredible Brightness of Seeing, a Home Theater weblog
http://www.anaze.us/HomeTheater
Jul 23 '05 #6
Jonathan Arnold wrote:
char c= 'a';

int i= c;

You don't need to do this, unless there is an overwhelming
desire to have the value as a signed int. char is merely
a (usually) smaller int.

This is a nice way with which a newcomer in C++ can "get the ASCII value of a character".
I think it is better than be told to cast the char to int when passed to cout.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
2265
by: Dan | last post by:
Some knows how to verify an ascii code. I want to verify a char for the list of ascii codes between 64 to 122. Mainly in other words, check a char, look if its in a range of ascii code and output a bool, true or false. thanks D
12
2644
by: wob | last post by:
Hi there, I wish to show some special characters such as the char for "alpha" and the symbol for degrees.. Anyone please give me some suggestions how to do that? Thank you very much! Owen
1
2580
by: James Dean | last post by:
i want to be able to get the correct ascii value from a byte without having to use the Convert.ToChar function as a char takes up two bytes of space and it is affecting the performance of my program. I know that for example the char value 'R' is '82' in byte form. What i want is to be able to translate byte numbers to their ascii equivalent...
3
32045
by: Director - Minvent | last post by:
Hi, I am reading from a serial port from a device which sends over an ascii character. It uses the full extended 256 character set and therefore has non-printing characters too. So what i want to do is convert the input to the associated decimal. I.E ASCII Char 'NUL' will become 0 ASCII Char 'SOH' will become 1
0
3698
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) : base(message){} public FtpException(string message, Exception innerException) : base(message,innerException){}
6
4068
by: ssetz | last post by:
Hello, For work, I need to write a password filter. The problem is that my C+ + experience is only some practice in school, 10 years ago. I now develop in C# which is completely different to me. But, the password filter needs to be built, so I'm doing my best. First of all, I am creating an xml string that contains both username and...
4
25044
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. Anybody please help in c language. Thanks in Advance.
9
4123
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string. What am I doing wrong? Dim plainText As String plainText = "tâ•e" Dim plainTextBytes() As Byte Dim enc As Encoding = Encoding.ASCII...
18
2965
by: nar0122 | last post by:
//Nicholas Riseden //CSCI 3300 //Assignment 4 Version 2 #include "tree.h" #include "pqueue.h" #include <string> #include <fstream> #include <iostream> #include <stdio.h>
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7698
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.