c++ - Tellg and seekg and file read not working -


i trying read 64000 bytes file in binary mode in buffer @ 1 time till end of file. problem tellg() returns position in hexadecimal value, how make return decimal value? because if conditions not working, reading more 64000 , when relocating pos , size_stream(size_stream = size_stream - 63999; pos = pos + 63999;), pointing wrong positions each time.

how read 64000 bytes file buffer in binary mode @ once till end of file?

any appreciated

  std::fstream fin(file, std::ios::in | std::ios::binary | std::ios::ate);     if (fin.good())     {         fin.seekg(0, fin.end);         int size_stream = (unsigned int)fin.tellg(); fin.seekg(0, fin.beg);         int pos = (unsigned int)fin.tellg();         //........................<sending file in blocks           while (true)         {             if (size_stream > 64000)             {                 fin.read(buf, 63999);                 buf[64000] = '\0';                 cstring strtext(buf);                 sendfilecontent(userkey,                     (lpctstr)strtext);                 size_stream = size_stream - 63999;                 pos = pos + 63999;                 fin.seekg(pos, std::ios::beg);             }             else             {                 fin.read(buf, size_stream);                 buf[size_stream] = '\0';                 cstring strtext(buf);                 sendfilecontent(userkey,                     (lpctstr)strtext); break;             }         } 

my problem tellg() returns position in hexadecimal value

no, doesn't. returns integer value. can display value in hex, not returned in hex.

when relocating pos , size_stream(size_stream = size_stream - 63999; pos = pos + 63999;), pointing wrong positions each time.

you shouldn't seeking in first place. after performing read, leave file position is. next read pick previous read left off.

how read 64000 bytes file buffer in binary mode @ once till end of file?

do more instead:

std::ifstream fin(file, std::ios::binary); if (fin) {     unsigned char buf[64000];     std::streamsize numread;         {         numread = fin.readsome(buf, 64000);         if ((!fin) || (numread < 1)) break;          // not send binary data using `lptstr` string conversions.         // binary data needs sent *as-is* instead.         //         sendfilecontent(userkey, buf, numread);     }     while (true); } 

or this:

std::ifstream fin(file, std::ios::binary); if (fin) {     unsigned char buf[64000];     std::streamsize numread;         {         if (!fin.read(buf, 64000))         {             if (!fin.eof()) break;         }         numread = fin.gcount();         if (numread < 1) break;          // not send binary data using `lptstr` string conversions.         // binary data needs sent *as-is* instead.         //         sendfilecontent(userkey, buf, numread);     }     while (true); } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -