This is called a cast operation. When the preceding statement executes, it prints the value 65 (on systems that use the ASCII character set). Write a program that prints the integer equivalent of a character typed at the keyboard. Store the input in a variable of type char. Test your program several times using uppercase letters, lowercase letters, dig- its and special characters (like $).
Here is a peek ahead. In this chapter you learned about integers and the type int. C++ can also represent uppercase letters, lowercase letters and a consider-
able variety of special symbols. C++ uses small integers internally to represent each different character. The set of characters a computer uses and the corresponding integer representations for those characters are called that computer’s character set. You can print a character by enclosing that char-
acter in single quotes, as with
cout << 'A'; // print an uppercase A
You can print the integer equivalent of a character using static_cast as follows:
cout << static_cast< int >( 'A' ); // print 'A' as an integer
```
#include
using namespace std; // program uses names from the std namespace
int main()
{
char symbol; // char read from user
cout << "Enter a character: "; // prompt user for data
cin >> symbol; // read the character from the keyboard
cout << symbol << "'s integer equivalent is "
<< static_cast< int >( symbol ) << endl;
} // end main
```
Enter a character: A
A's integer equivalent is 65
Enter a character: B
B's integer equivalent is 66
Enter a character: a
a's integer equivalent is 97
Enter a character: 7
7's integer equivalent is 55
Enter a character: $
$'s integer equivalent is 36
You might also like to view...
Which statement tests the value of an expression once and then uses that value to determine the result?
a. Nested If b. If...Then...ElseIf c. If...Then d. Select Case
Which of the following statements is true of creating a copy of a query in Microsoft Access 2016??
A. ?Existing queries cannot be duplicated. B. ?An existing query can be copied but cannot be renamed. C. ?Creating a new query from scratch is faster than copying a query. D. ?A query can be copied and pasted in the Navigation Pane.
Incident ____________________ is the set of activities taken to plan for, detect, and correct the impact of an incident on information assets.
Fill in the blank(s) with the appropriate word(s).
If a digital subscriber line is ____, it does not have the same transmission speed in the download direction as in the upload direction.
virtual asymmetric symmetric encoded