Hello CodeCall Members,
Today I'd like to Show you How to Make a Simple Program that Will Print us the ASCII Code .. using C++ ..
Ok..! ,
First of all we declare 2 variables .. ('i' as an integer and 'a' as a character)
then we use this loop:Code:int i; char a;
the "i" starts from 30 because the other characters before 30 are some special characters (like ENTER etc..) .. so we say that from i=30 till i<=255 increasing the 'i' for 1 ..Code:for (i=30;i<=255;i++)
the 'a' character becomes the character with the ASCII code 'i' .. using this command ..
now, using "iomanip" we format the output .. the iomanip code will look like as following:Code:a=i;
Code:cout << setw(2) << a << setw(6) << i;
.. the "setw(2) will reserve 2 spaces for the character 'a' .. and setw(6) will reserve 6 spaces for the number 'i' ..
finally the code will look like the following:
Code:#include <iostream> #include <iomanip> using namespace std; int main() { int i; char a; for (i=30;i<=255;i++) { a=i; cout << setw(2) << a << setw(6) << i; } cout << endl; return 0; }
.. and the console application will look like the following:
..
Thanks,
Egz0N ..
Last edited by Egz0N; 11-28-2009 at 03:07 AM.
Nice and simple, I like it. +rep
Nice way to generate a quick ASCII table.
![]()
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)
Interesting, but, what are ASCII values?
The American Standard Code for Information Interchange (acronym: ASCII) is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text. Most modern character-encoding schemes, which support many more characters than did the original, are based on ASCII.
Nicely written! Simple and easy to follow. +rep
thanks ..![]()
A lot of C++ coders don't even know iomanip exists. Your tutorial appeases me, but it would be clearer if you cast i to a char first.
Not necessary, maybe, but clearer.Code:a = (char) i;
Anyway, great little tutorial! Plus rep
Wow I changed my sig!
ahh .. thanks ..![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks