[問題] basic_ifstream & istreambuf_iterator
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
MSVS 2010
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
STL
問題(Question):
下面程式碼總是沒有完整的把檔案讀完印出來
餵入的資料(Input):
一個 (檔案大小%4==0) 的二進制檔案, 其中含有 0xFFFFFFFF 在 (位置%4==0) 的地方
預期的正確結果(Expected Output):
將檔案內容完整印出
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
std::basic_ifstream<unsigned int> file ("1.bin", std::ios::binary);
std::for_each (std::istreambuf_iterator<unsigned int> (file),
std::istreambuf_iterator<unsigned int>(),
[] (const unsigned int &value) {
std::cout << "0x" << std::setw (8) << std::setfill ('0') << std::hex
<< value << std::endl;
});
補充說明(Supplement):
看起來只要讀到和 std::char_traits<unsigned int>().eof() 相同的值
0xffffffff
for_each 就會提前離開, 請問如何如何修正?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.233.6.158
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1430003778.A.F48.html
推
04/26 12:08, , 1F
04/26 12:08, 1F
→
04/26 12:08, , 2F
04/26 12:08, 2F
→
04/26 12:09, , 3F
04/26 12:09, 3F
推
04/26 12:42, , 4F
04/26 12:42, 4F
→
04/26 12:42, , 5F
04/26 12:42, 5F
→
04/26 12:44, , 6F
04/26 12:44, 6F
→
04/26 12:45, , 7F
04/26 12:45, 7F
→
04/26 12:46, , 8F
04/26 12:46, 8F
→
04/26 12:47, , 9F
04/26 12:47, 9F
→
04/26 12:48, , 10F
04/26 12:48, 10F
→
04/26 12:49, , 11F
04/26 12:49, 11F
→
04/26 13:32, , 12F
04/26 13:32, 12F
→
04/26 13:33, , 13F
04/26 13:33, 13F
→
04/26 13:33, , 14F
04/26 13:33, 14F
→
04/26 13:40, , 15F
04/26 13:40, 15F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章