1: //char_int_conversion.cpp 2: //Illustrates some local character codes on your system 3: //and conversion between "int" and "char" data values. 5: #include <iostream> 6: #include <iomanip> 7: using namespace std; 9: int main() 10: { 11: cout << "\nThis program shows the int and char values for some " 12: "of the characters\nin your local character set, and how to " 13: "convert between them.\n"; 14: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 16: char charValue; 17: cout << "\nEnter any upper or lower case letter, digit, " 18: "or punctuation character: "; 19: cin >> charValue; cin.ignore(80, '\n'); 20: cout << "The internal integer value corresponding to " << charValue 21: << " is " << static_cast<int>(charValue) << ".\n"; 22: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 24: int intValue; 25: cout << "\nEnter an integer value from the range " 26: << static_cast<int>('A') << ".." << static_cast<int>('Z') 27: << ": "; 28: cin >> intValue; cin.ignore(80, '\n'); 29: cout << "The capital letter corresponding to " << intValue 30: << " is " << static_cast<char>(intValue) << ".\n"; 31: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 33: cout << "\nEnter an integer value from the range " 34: << static_cast<int>('a') << ".." << static_cast<int>('z') 35: << ": "; 36: cin >> intValue; cin.ignore(80, '\n'); 37: cout << "The lowercase letter corresponding to " << intValue 38: << " is " << static_cast<char>(intValue) << ".\n"; 39: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 41: cout << "\nEnter an integer value from the range " 42: << static_cast<int>('0') << ".." << static_cast<int>('9') 43: << ": "; 44: cin >> intValue; cin.ignore(80, '\n'); 45: cout << "The digit character corresponding to " << intValue 46: << " is " << static_cast<char>(intValue) << ".\n"; 47: cout << endl; 49: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 50: }