473,224 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

[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 8667
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
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...
12
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
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...
3
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...
0
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) :...
6
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....
4
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. ...
9
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....
18
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>
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.