- 最後登錄
- 2022-8-30
- 在線時間
- 1 小時
- 註冊時間
- 2017-4-15
- 閱讀權限
- 20
- 精華
- 0
- UID
- 6899596
- 帖子
- 0
- 積分
- 0 點
- 潛水值
- 580 米
| 成為伊莉的版主,你將獲得更高級和無限的權限。把你感興趣的版面一步步地發展和豐盛,那種滿足感等著你來嚐嚐喔。 最後我把文字檔的0x去掉中間空一格又換行
00000000 00011428
00000004 00010068
00000008 00000264
0000000c 00006000
00000010 00001362
00000014 05bcd4f6
00000018 053c42f4
0000001c 053ca2f6
00000020 0593f05b
00000024 01bc82f7
但讀入檔案再輸出還是一樣是錯的...
是因為空格和換行的關係嗎?
-
- #include<iostream>
- #include<fstream>
- using namespace std;
- int main()
- {
-
- unsigned long b,c;
- ifstream fin;
- fin.open("a.txt");
-
- while(!fin.eof())
- {
-
- fin >> hex >> b >> c;
- cout << hex << b << " " << c << endl;
-
- }
-
- system("pause");
- return 0;
-
- }
複製代碼
改存成bin檔,如圖
程式碼改成,輸出結果也一樣是錯的...請問這是為何?
-
- #include<iostream>
- #include<fstream>
- using namespace std;
- int main()
- {
-
- unsigned long b,c,d,e;
- ifstream fin;
- fin.open("a.bin");
-
- while(!fin.eof())
- {
-
- fin.read(reinterpret_cast<char*>(&b),sizeof(unsigned long));
- fin.read(reinterpret_cast<char*>(&c),sizeof(unsigned long));//讀空格
- fin.read(reinterpret_cast<char*>(&d),sizeof(unsigned long));
- fin.read(reinterpret_cast<char*>(&e),sizeof(unsigned long));//讀空格
-
-
- cout << hex << b << " " << d << endl;
-
- }
- system("pause");
- return 0;
-
複製代碼 ... |
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊 |