convert into acsii c++
To convert a character into its ASCII value in C++, you can use the built-in function int()
or typecast the character to an integer. Here is an example:
#include <iostream>
using namespace std;
int main() {
char c = 'A';
int asciiValue = int(c);
cout << "The ASCII value of " << c << " is: " << asciiValue << endl;
return 0;
}
Explanation:
1. We include the <iostream>
library to use the cout
object for displaying output.
2. We declare a variable c
of type char
and assign it the value 'A'
.
3. We declare a variable asciiValue
of type int
to store the ASCII value.
4. We use the int()
function to convert the character c
to an integer and assign it to asciiValue
.
5. We use the cout
object to display the message "The ASCII value of A is: " followed by the value of asciiValue
.
6. Finally, we return 0 to indicate successful program execution.
Note: In this example, we convert the character 'A' to its ASCII value. You can change the character c
to any other character to get its corresponding ASCII value.