文件的is_ascii()或is_binary()? [英] is_ascii() or is_binary() for files?

查看:107
本文介绍了文件的is_ascii()或is_binary()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法确定文件是否是纯文本ascii文本

使用标准C ++?

Is there a way to determine whether a file is plain ascii text or not
using standard C++?

推荐答案

"布拉德"写道:
"Brad" wrote:

有没有办法确定文件是否是普通的ascii文本

使用标准C ++?
Is there a way to determine whether a file is plain ascii text or not
using standard C++?



否。这是在旁观者的眼中。你可以通过计算不太可能出现在文本中的控制字符来对

进行非常好的猜测。但

存在二进制文件可能也没有任何一个的可能性。

No. It''s in the eye of the beholder. You can make a very good guess by
looking by counting control characters that wouldn''t likely be in text. But
the possibility exists that a binary file might not have any of them either.


Brad< br ** @ 16systems.comwrites:
Brad <br**@16systems.comwrites:

有没有办法确定文件是否是普通的ascii文本

使用标准C ++?
Is there a way to determine whether a file is plain ascii text or not
using standard C++?



当然,只需阅读其内容并查找任何字节为127.如果

你找到一个,那么文件'' s内容不是纯ASCII。


sherm--


-

我的博客: http://shermspace.blogspot.com

Perl中的Cocoa编程:< a rel =nofollowhref =http://camelbones.sourceforge.nettarget =_ blank> http://camelbones.sourceforge.net


7月5日上午11点22分,Sherman Pendley< spamt ... @ dot-app.orgwrote:
On Jul 5, 11:22 am, Sherman Pendley <spamt...@dot-app.orgwrote:

Brad< b ... @ 16systems.comwrites:
Brad <b...@16systems.comwrites:

有没有办法确定文件是否是普通的ascii文本

使用标准C ++?
Is there a way to determine whether a file is plain ascii text or not
using standard C++?



当然,只需阅读其内容并查找任何字节为127.如果

你找到一个,那么文件'' s内容不是纯ASCII。


Sure, just read its contents and look for any byte that''s 127. If
you find one, the file''s contents are not plain ASCII.



如果他试图在包含非英文文本的文本文件中进行测试,他将会失败!

将失败!!

因为非英语字符是127

if he try to test in a text file which contain non-English text , he
will fail!!
because non-English char are 127


这篇关于文件的is_ascii()或is_binary()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆