c++ - Missed characters in cout_ing? -


i'm trying make code can convert image binary(o-1) , worked there many symbols (ascii characters) missed in result of code while when open image in hex editor find full image converted , find these characters converted , , when tried make counter beside every binary comes out , noticed counter stops before missed character , starts again after passing it. here code..

#include <string> #include <bitset> #include <iostream> #include<fstream> using namespace std; int main() {    ifstream file("e:\\2.jpg");    string mystring;    ofstream fout("e:\\mnmn.txt");    while(file>>mystring)    {    (size_t = 0; < mystring.size(); ++i)    {   fout <<i <<"-"<< bitset<8>(mystring.c_str()[i])<<endl;  }} return 0; 

}

the result comes out like:

0-11111111 1-11011000 2-11111111 3-11100000 4-00000000 5-00010000 0-01001010    \\passed 00001001 character , started counter beginig 1-00000000 etc... 

thank in advance help.

you trying read std::string binary file (and not opening file ios::binary). [binary file = "not text"]

you should use stream::read read data binary file. std::string , operator >> aren't meant read raw binary data, , not work purpose.

the reason stops reading , skips on byte 00001001 is "whitespace character" - tab in particular case. can stop skipping whitespace file >> noskipws >> something;, doesn't fact will, always, stop reading @ newline. since can't guarantee jpg file doesn't contain byte newline, it's impossible process jpg files using operator>> strings.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -