How to identify the file content as ASCII or binary

后端 未结 10 2583
旧巷少年郎
旧巷少年郎 2020-11-28 05:54

How do you identify the file content as being in ASCII or binary using C++?

10条回答
  •  旧时难觅i
    2020-11-28 06:06

    The contents of every file is binary. So, knowing nothing else, you can't be sure.

    ASCII is a matter of interpretation. If you open a binary file in a text editor, you see what I mean.

    Most binary files contain a fixed header (per type) you can look for, or you can take the file extension as a hint. You can look for byte order marks if you expect UTF-encoded files, but they are optional as well.

    Unless you define your question more closely, there can't be a definitive answer.

提交回复
热议问题