How do I access the elements of a string?
<p>I am having trouble accessing the individual characters of the binary string to do find out whether they are set or not, what am I doing wrong? Or is there an easier way? Here is my code:</p>

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

using namespace std;

float BinToDec(const string &amp; bin) {
    short length = bin.length();
    float result = 1.0f;

    const char * str = bin.c_str();

    for (int i = 0; i &lt; length; ++i) {
        if ( &amp;str[i] == "1") cout &lt;&lt; "SET" &lt;&lt; endl &lt;&lt; endl;
        else cout &lt;&lt; "NOT SET" &lt;&lt; endl &lt;&lt; endl;
    }

    return result;
}

int main() {

    string bin = "";

    cout &lt;&lt; "Input a binary number: ";
    cin &gt;&gt; bin;

    cout &lt;&lt; BinToDec(bin) &lt;&lt; endl &lt;&lt; endl;

}
</code></pre>
