I have written VERY simple code that converts a string to a character array and then displays the ASCII value of each character. Let me know if this is the most effective/safe way of doing what I described above.
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
//Declare Variables.
string input;
int size;
//Display message to user asking them to enter a string or character.
cout << "What character/string do you need the ascii value(s) of? " << endl;
//Assign user input to string input.
cin >> input;
//Get string length of user input.
size = input.length();
//Copy the string into a character array.
const char * chars = input.c_str();
//Itterate through the character array using the string size.
for(int i = 0; i < size; i++){
//Return Ascii values of each character.
cout << "The value of character " << chars[i] << " is " << (int)chars[i] << endl;
}
return 0;
}
gets.chomp.chars.each {|char| print "The ASCII value of #{char} is #{char.ord}\n"}
Is the same as your program but in Ruby, just for comparison... \$\endgroup\$