[C++] extract the RGB values - convert to binary[C++] extract the RGB values - convert to binary

🖼️

Steganographia

Week 9, 2026

#include #include #include #include #include using namespace std; // get RGB values from another utility I had to write, using stb_image.h from: // https://github.com/nothings/stb/blob/master/stb_image.h std::string rgbToBinary(int r, int g, int b) // convert RGB to binary<8>bits { if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { return "Invalid RGB value"; } cout << std::bitset<8>(r).to_string(); return std::bitset<8>(r).to_string(); } int main() { string fline, conv = ""; string convR,convG,convB = ""; int iR,iG,iB = 0; vector vred; vector vgreen; vector vblue; fstream outputfile;//"linked" is the filename of output from that other utility outputfile.open("linked", ios::out | ios::in | ios::app); if (!outputfile.is_open()) { cout << "Error: Unable to open \"linked\"!\n"; return false; } else { while(getline(outputfile, fline)) { convR = fline; vred.push_back(convR); convG = fline; vgreen.push_back(convG); convB = fline; vblue.push_back(convB); } for(int i = 0; i < vred.size(); i++) { //uses vector's index iR = stoi(vred[i]); iG = stoi(vgreen[i]); iB = stoi(vblue[i]); conv = rgbToBinary(iR, iG, iB);// just to run function } } return 0; } //EOF