Introduction To Character Sets
The C++ character set comprises alphabets, special symbols, digits, and whitespace characters that are recognized and accepted by C++ programs. These elements are utilized to form commands, expressions, identifiers, and other language constructs within C++.
In addition to standard characters, C++ also employs special character combinations to represent particular conditions. For instance, '\n' denotes a newline, '\b' represents a backspace, and '\t' signifies a horizontal tab.
The character set in C++ can be broadly categorized into four groups:
- Letters: Alphabets from A-Z and a-z. Note that uppercase and lowercase letters are distinct in C++.
- Digits: Numeric digits from 0 to 9.
- Special Symbols: Various symbols such as +, -, *, /, %, ^, &, |, ~, !,
<, >, =, ( ), [, ], , ;, :, ,, ., ?, ', ", , #, $, @, etc. - Whitespace: Blank space, horizontal tab, carriage return, newline.
Example of C++ Character Set Usage
Below is an example C++ program demonstrating the use of character sets:
#include<iostream>
using namespace std;
int main() {
char letter, digit, specialCharacter;
cout << "Enter a letter: ";
cin >> letter;
cout << "You entered a letter: " << letter << endl;
cout << "\nEnter a digit: ";
cin >> digit;
cout << "You entered a digit: " << digit << endl;
cout << "\nEnter a special character: ";
cin >> specialCharacter;
cout << "You entered a special character: " << specialCharacter << endl;
return 0;
}Output:-
Enter a letter: e
You entered a letter: e
Enter a digit: 7
You entered a digit: 7
Enter a special character: @
You entered a special character: @This program allows the user to input a letter, a digit, and a special character, demonstrating the utilization of various elements from the C++ character set.