How do you do change from one variable to another?
<p>I have a few questions:</p>

<ol>
<li>How do you get a certain char from a string?</li>
<li>How do you get a char to a int?</li>
<li>How do you get a int to a char?</li>
<li>How do you append a char to a string?</li>
</ol>

<p>I was just making a simple keyed cipher... just playing around to learn cpp. I do know java so if you could relate to that it would be great!</p>

<p>Here is my code so please tell me how to improve... thanks! :)</p>

<pre><code>#include &lt;string&gt;

using namespace std;

string encrypt(string data, string pass) {
    // Use a Keyed Cipher //
    string encrypted;
    int index = 0;
    for (int x = 0; x &lt; sizeof(data); x++) {
        int tmp = static_cast&lt;int&gt;(data.substr(x));
        int tmpPass = static_cast&lt;int&gt;(pass.substr(index));
        tmp += tmpPass;

        if (tmp &gt; 126) {
            tmp -= 95;
        }

        if (index &gt; sizeof(pass)) {
            index = 0;
        }
        encrypted += static_cast&lt;char&gt;(tmp);
    }
    return data;
}
</code></pre>
