I have updated my "hash2binary" thing (remember that?), so that it will count how many 1s are in the binary. Here is what I have so far.
#include <iostream>
#include <fstream>
#include <string>
#include <bitset>
using namespace std;
int main() {
int oneCount = 0;
cout << "Hash: ";
string str;
string temp;
getline(cin, str);
fstream file;
file.open("file.txt");
for(int i = 0; i < str.length(); i++) {
// cout << str[i] << ": " << bitset<8>(str[i]) << "\n";
cout << bitset<8>(str[i]);
file << bitset<8>(str[i]);
}
for(int i = 0; i <= 8 * str.length(); i++) {
if() { // What to put in if?
oneCount++;
}
}
cout << "\n" << oneCount << " 1s out of " << 8 * str.length() << "\n";
file.close();
return 0;
}
As you can see in the comment, I have no idea how to check if the file character i if a 1 or not. Does anyone know how? (I am relatively new with outputting files)
GEOFBOT

New Topic/Question
Reply



MultiQuote




|