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:
#include <iostream> #include <string> using namespace std; float BinToDec(const string & bin) { short length = bin.length(); float result = 1.0f; const char * str = bin.c_str(); for (int i = 0; i < length; ++i) { if ( &str[i] == "1") cout << "SET" << endl << endl; else cout << "NOT SET" << endl << endl; } return result; } int main() { string bin = ""; cout << "Input a binary number: "; cin >> bin; cout << BinToDec(bin) << endl << endl; }