Alright, so I am very new to c++ and I just felt like doing a little encryption experiment. In about ten seconds of thinking I've decided that for my encryption I want to:

Get the ASCII value of a string of text entered by the user, and store it in a variable...
Get a key also supplied by the user and store that into a variable.
Take the two variables, send them through an algorithm, and spit out the result.

Simple.

My problem is that I cannot seem to figure out how to convert the text into an ASCII value.
Any thoughts?

Thanks

I was trying to understand what's the ASCII value of a string of text (about 10 seconds or even more)... Alas... Can you explain what is it?

Now I see why you cannot seem to figure out how to convert the text into an ASCII value.

However if you want to get int value of a single char, that's it:

char c = '!';
int  i = c;
// or (int)c
Comments
Maybe he meant: ASCII - A whole S(tring) C(onversion) to I(ntegral) I(ntegers)... :)
LOL, The ASCII value of a string :D

I was trying to understand what's the ASCII value of a string of text (about 10 seconds or even more)... Alas... Can you explain what is it?

Now I see why you cannot seem to figure out how to convert the text into an ASCII value.

However if you want to get int value of a single char, that's it:

char c = '!';
int  i = c;
// or (int)c

Im not sure that I follow what you are saying....:/

What I want to do is get the ASCII value of a letter, (all the letters in a string) and store it in a variable that I can call on later and manipulate....

Hope that clears things up...

Have you ever read my post above? What's ascii value of all letters in a string? Didn't you understand that it's a nonsense?
Well, probably your string value contains in a (string) variable. What's a problem? Manipulate it as you wish!

Ok here is the code i have right now....Anyone want to help guide me?
ArkM uh, I really don't have the knowledge of c++ to understand what you are trying to explain...It seems like english isn't your native language...
Anyways...Im not sure if im completely missing something, but how what I convert each letter to ASCII values then store these values to use in an algorithm.

#include <iostream>
#include <string>

using namespace std;
void conv_1(int c);
void alg_1(int z);

int convers;
int algor;

int main ()
{
    string word;
    int a = 0;
    int key = 0;
    cout<<"Enter text to encrypt \n :";
    cin>> word;
    cout<<"Enter encryption key \n :";
    cin>> key;
    
    conv_1();
    alg_1();
    cout<<"the encrypted text is:"<<z;
    system("PAUSE");
    return 0;
}
    
    
void conv(int c)
{
     // Conversion anyone?
       
}

void alg(int z)
{
     //havent come up with one yet... :P
}

Hmm,,,,Still cant seem to figure out what your are trying to do here. My question would be do you want to separate each character of the string and encrypt it?? If so the conversion is as ArkM mentioned earlier for example take "abcd"

If you want ascii value of c then use

int i = (int)word[2];
//now i will contain the ascii value of the character 'c'

If this is not what you want then let me know

Fortunately, you write a program in C++, not in English (you write nonsense phrases like ascii value of a string in English).

Now you have a single word (not a typed text) in the string word: cin >> word inputs a word and stops on the 1st space after the word. The next cin >> key inputs the next word. For example, if an user typed Text to be encripted then word == "Text" and key == "to". Is it a desired effect? If it is not, read about std::getline function in your textbook:

getline(cin,word);
// then
getline(cin,key);

Well, suppose you have right word and key contents. They both are local (in main) string variables. Now you are trying to call conv_1() and alg_1() functions without arguments. But you didn't declare these functions. Just before main you declare another functions: conv_1 with int parameter and alg_1 with int parameter. After main you define yet another two functions: conv and alg. What's a wonderful functional zoo!

Are you sure that you are ready to encrypt/decrypt that mysterious ascii value of a string? Probably you want to learn C++ basic concepts on-line?

This article has been dead for over six months. Start a new discussion instead.