我们可以自己写一个EOF字符吗? [英] Can we write an EOF character ourselves?

查看:131
本文介绍了我们可以自己写一个EOF字符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在写入文件时,大多数语言(如C ++)都会使用EOF字符,即使我们错过编写以下语句:



filestream.close



但是有什么办法,我们可以根据我们的要求,在C ++中为一个实例放置EOF字符。
或者除了使用C ++中提供的函数之外,我们还可以使用任何其他方法。



如果你需要更多的信息,那么请做评论。



提前感谢。



编辑:感谢您的支持, p>

如果我们想欺骗操作系统并在文件中放置一个EOF字符,并在EOF之后写入一些数据,以便像notepad.exe这样的应用程序无法读取后我们的EOF字符。
我已经阅读了与这个主题相关的问题的答案,并且已经知道现在的操作系统通常不会看到一个EOF字符,而是检查文件的长度,以获得正确的想法知道的长度文件,但在操作系统中必须有一个过程,它将检查文件的长度,然后更新文件记录。



对不起,如果我在任何时候错了在我的估计,但请帮助我coz它可以导致许多新的想法。



谢谢。

解决方案

没有EOF字符。 EOF通过定义不等于任何有效的字符代码。通常是-1。



在DOS中有一个历史EOF字符值(CTRL + Z),但这些日期已过时。



要回答Apoorv的后续问题:操作系统从不使用文件数据来确定文件长度(文件不是任何方式)。所以你不能欺骗操作系统。也许老,愚蠢的程序不会读取CTRL + Z字符后。我不会假设任何Windows应用程序(甚至记事本)都会这样做。我的猜测是,使用null( \0 )字符来欺骗他们会更容易。


Most of the languages like C++ when writing into a file, put an EOF character even if we miss to write statements like :

filestream.close

However is there any way, we can put the EOF character according to our requirement, in C++, for an instance. Or any other method we may use apart from using the functions provided in C++.

If you need to ask more of information then kindly do give a comment.

Thanks in advance.

EDIT: Thanks for your support but here's an addition to this question:

What if, we want to trick the OS and place an EOF character in a file and write some data after the EOF so that an application like notepad.exe is not able to read after our EOF character. I have read answers to the question related to this topic and have come to know that nowdays OS generally don't see for an EOF character rather check the length of file to get the correct idea of knowing about the length of the file but, there must be a procedure in OS which would be checking the length of file and then updating the file records.

I am sorry if I am wrong at any point in my estimation but please do help me coz it can lead to a lot of new ideas.

Thanks.

解决方案

There is no EOF character. EOF by definition "is unequal to any valid character code". Often it is -1. It is not written into the file at any point.

There is a historical EOF character value (CTRL+Z) in DOS, but it is obsolete these days.

To answer the follow-up question of Apoorv: The OS never uses the file data to determine file length (files are not 'null terminated' in any way). So you cannot trick the OS. Perhaps old, stupid programs won't read after CTRL+Z character. I wouldn't assume that any Windows application (even Notepad) would do that. My guess is that it would be easier to trick them with a null (\0) character.

这篇关于我们可以自己写一个EOF字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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