String into ASCII

I am making a text encrypter and I have a good idea of converting text into ASCII codes. I know how to convert a single character into ASCII -

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main()
{
cout<<"Text to ASCII converter"<<endl<<"Enter text to convert into ASCII - ";
char text;   //defining input type, which is single character
int ascee;   //defining that ASCII code will be numeric integer
cin>>text;   //taking input from user
ascee = static_cast<int>(text);//converting the input character into ASCII code
cout<<endl<<"ASCII code is "<<ascee<<endl; //displaying the ASCII code
return 0;
}


Try it here - http://bit.ly/cppASCII (But in ideone, you can't give input so it's better to try in your own compiler)

Is there any way to run a similar program, which converts a string with spaces into ASCII code?
StarSonic7 wrote:
(But in ideone, you can't give input so it's better to try in your own compiler)
You can give input, there is a box underneath where you enter the code.


I don't understand why you cannot simply loop through a string and convert each character to an int.

Do keep in mind, however, that different operating systems, different compilers, and different character encodings assign different values to characters, and ASCII is almost never used these days.
Topic archived. No new replies allowed.