看板 b94902HW 關於我們 聯絡資訊
昨天有同學問到: fopen的 mode 如果只用 "r" 而不是用 "rb",為什麼批改魔會對? 根據 manpage 的訊息,我節錄一段給各位看: The mode string can also include the letter ‘‘b’’ either as a last character or as a character between the characters in any of the two-character strings described above. This is strictly for compatibility with ANSI X3.159-1989 (‘‘ANSI C’’) and has no effect; the ‘‘b’’ is ignored on all POSIX conforming systems, including Linux. (Other systems may treat text files and binary files differently, and adding the ‘‘b’’ may be a good idea if you do I/O to a binary file and expect that your program may be ported to non-Unix environments.) 簡單地說,POSIX-compliant 的作業系統下,"b" mode 是可以不必使用的 (批改魔的作業系統是 Linux ),但如果在 non-UNIX 環境下有可能會有問題。 所以我才會建議大家針對 binary file 應該要加上 "b" 。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.30.82