C++ - Issue when using .at() method with string
<p>I have tried Googling and trying everything I can think of, but I can't overcome the problem. So I have come to the masters at StackOverflow!</p>

<p>I am having trouble using the .at() string method:</p>

<pre><code>std::string letters = "QWERTYUIO";

// &amp;(letters.at(0)) now evaluates to QWERTYUIO
// &amp;(letters.at(5)) now evaluates to YUIO
// etc.
</code></pre>

<p>What I want is the nth character of the string, not a string starting at the nth character.</p>

<p>I tried the [] operator, but I now have a new problem. The code is currently (using the Allegro library, but I don't think that is affecting this):</p>

<pre><code>std::string letters = "QWERTYUIO";
char letter;
char StringY[5];
int row = 0;

for(int l = 0; l &lt;= 2; ++l){
    letter = letters[row + l];

    textout_ex(buffer, font, &amp;letter, l * 30, 20, makecol(255, 255, 255), -1);

    sprintf(StringY, "%d", inventoryNum[row + l + 9]);
    textout_ex(buffer, font, StringY, l * 30, 20, makecol(255, 255, 255), -1);
}
</code></pre>

<p>What is happening is the letter variable seems to be appending the StringY of the previous iteration to itself for no apparent reason. This is driving me insane.</p>

<p>Any help is appreciated.</p>

<p>Many thanks,</p>

<p>Will.</p>
