convert string to ASCII value
I was new to C++. I trying to convert a string(example : hello) into ASCII value. I tried to use putchar(0, but it only work for one character.
if I want to declare the char string become char string[80], then what are the following steps should I take??? Thank you for your time.
# include <iostream.h>
# include <string.h>
# include <stdio.h>
void main(){
char string;
cout<<"Enter a string : ";
cin>>string;
cout<<"The string you entered is "<<string<<endl;
cout<<"The ASCII value for that string is "<<putchar(string);
}
Re: convert string to ASCII value
Code:
char string[80];
cout<<"Enter a string : ";
cin.getline(string,80,'\n');
display ASCII vaue of a string
# include <iostream.h>
void main(){
char string[80];
cout<<"Enter a string : ";
cin.getline(string,80,'\n');
cout<<"The string you entered is "<<string<<endl;
cout<<"The ASCII value for that string is "<<string;
}
if what I want to display is the ASCII value of H+e+l+l+o = ??, which line in the coding should I change? thank you.