How to identify the file content as ASCII or binary

后端 未结 10 2582
旧巷少年郎
旧巷少年郎 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 05:58

    Well, this depends on your definition of ASCII. You can either check for values with ASCII code <128 or for some charset you define (e.g. 'a'-'z','A'-'Z','0'-'9'...) and treat the file as binary if it contains some other characters.

    You could also check for regular linebreaks (0x10 or 0x13,0x10) to detect text files.

提交回复
热议问题