How can I write an array that lists the elements as alpha letters instead of numbers?
Like this:
NOT like this:Code:Element Value a 45 b 5 c 655
Code:Element Value 0 45 1 5 2 655
How can I write an array that lists the elements as alpha letters instead of numbers?
Like this:
NOT like this:Code:Element Value a 45 b 5 c 655
Code:Element Value 0 45 1 5 2 655
Last edited by bond_006; 05-02-2010 at 03:48 PM.
Do you mean store chars instead of ints? If so, then you just denote the type when creating the array.
oops, just posted before you edited. I don't think you can do what you want (I may be wrong as i am new to programming), but the 0,1,2 etc is the element within the array.
Maybe somebody else could clarify.
No, I want the array to store integer values, I just want to display the Element number of the array as an alpha letter (character) instead of an integer.
Kind of like this:
Code:Element Value a 45 b 22 c 7554
Code:int nums[4] = {1, 2, 3, 4}; for ( int i = 0; i < sizeof( nums ) / sizeof( int ); ++i ) { std::cout << nums[i] << std::endl; }
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
A simple ascii table look up will suffice. The character 'a' starts at 97 on the table. Just add that number to each of the element indexes and voila. Also a typecast will be in order to display it as a character.
Do you want to store the real ASCII values of the characters, or those numbers that you made up?
If you want the real ASCII values, just have an array of chars and if you need the ASCII number, just cast each char to an int when you display it.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010