不包含stdio.h头文件,怎么读写文件
不包含stdio.h头文件,如何读写文件
MISRA-C 2004标准中说,
“规则 20.9(强制): 在产品代码中不应使用输入/输出库<stdio.h>。
[未指定 2-5,16-18;未定义 77-89;实现 53-68]
这包含文件和I/O 函数fgetpos、fopen、ftell、gets、perror、remove、rename 和ungetc。
64
流和文件I/O 具有大量未指定的、未定义的和实现定义的行为。本文档中假定正常情况下
嵌入式系统的产品代码中不需要它们。
如果产品代码中需要 stdio.h 中的任意特性,那么需要了解与此特性相关的某些问题。”
如果这样,那么在c语言中,读写文件该怎么实现,我都是用fopen打开文件的啊~求解~~~
------解决思路----------------------
那就用系统提供的文件操作啊,windows(Windows.h)有CreateFile,ReadFile;linux(fcntl.h, unistd.h)有open,read,write,close。
------解决思路----------------------
Low-level I/O
These functions invoke the operating system directly for lower-level operation than that provided by stream I/O. Low-level input and output calls do not buffer or format data.
Low-level routines can access the standard streams opened at program startup using the following predefined handles:
Stream Handle
stdin 0
stdout 1
stderr 2
Low-level I/O routines set the errno global variable when an error occurs. You must include STDIO.H when you use low-level functions only if your program requires a constant that is defined in STDIO.H, such as the end-of-file indicator (EOF).
Low-Level I/O Functions
Function Use
_close Close file
_commit Flush file to disk
_creat, _wcreat Create file
_dup Return next available file handle for given file
_dup2 Create second handle for given file
_eof Test for end of file
_lseek, _lseeki64 Reposition file pointer to given location
_open, _wopen Open file
_read Read data from file
_sopen, _wsopen Open file for file sharing
_tell, _telli64 Get current file-pointer position
_umask Set file-permission mask
_write Write data to file
_dup and _dup2 are typically used to associate the predefined file handles with different files.
------解决思路----------------------
这明明是C函数,你怎么说是C++函数呢?
------解决思路----------------------
单独使用一个 C 文件,使用 stdio.h.
她们仅仅是定义。
------解决思路----------------------
那个标准不是说的很清楚吗? 就是说,标准本身是假定你没有stdio.h中规定的i/o需求的。而现在你有读写文件的需求,因此,需要你的嵌入式系统支持你读写文件这类操作。对于标准情况而言,这类操作可能包含大量为定义的行为,因此,至于如何使用,只有从你的系统本身那里找答案。
ps:提示一下,怎么读写文件要看你的文件系统接口,如果你的系统里根本没有文件系统,那么就不能读写文件。
MISRA-C 2004标准中说,
“规则 20.9(强制): 在产品代码中不应使用输入/输出库<stdio.h>。
[未指定 2-5,16-18;未定义 77-89;实现 53-68]
这包含文件和I/O 函数fgetpos、fopen、ftell、gets、perror、remove、rename 和ungetc。
64
流和文件I/O 具有大量未指定的、未定义的和实现定义的行为。本文档中假定正常情况下
嵌入式系统的产品代码中不需要它们。
如果产品代码中需要 stdio.h 中的任意特性,那么需要了解与此特性相关的某些问题。”
如果这样,那么在c语言中,读写文件该怎么实现,我都是用fopen打开文件的啊~求解~~~
------解决思路----------------------
那就用系统提供的文件操作啊,windows(Windows.h)有CreateFile,ReadFile;linux(fcntl.h, unistd.h)有open,read,write,close。
------解决思路----------------------
Low-level I/O
These functions invoke the operating system directly for lower-level operation than that provided by stream I/O. Low-level input and output calls do not buffer or format data.
Low-level routines can access the standard streams opened at program startup using the following predefined handles:
Stream Handle
stdin 0
stdout 1
stderr 2
Low-level I/O routines set the errno global variable when an error occurs. You must include STDIO.H when you use low-level functions only if your program requires a constant that is defined in STDIO.H, such as the end-of-file indicator (EOF).
Low-Level I/O Functions
Function Use
_close Close file
_commit Flush file to disk
_creat, _wcreat Create file
_dup Return next available file handle for given file
_dup2 Create second handle for given file
_eof Test for end of file
_lseek, _lseeki64 Reposition file pointer to given location
_open, _wopen Open file
_read Read data from file
_sopen, _wsopen Open file for file sharing
_tell, _telli64 Get current file-pointer position
_umask Set file-permission mask
_write Write data to file
_dup and _dup2 are typically used to associate the predefined file handles with different files.
------解决思路----------------------
这明明是C函数,你怎么说是C++函数呢?
------解决思路----------------------
单独使用一个 C 文件,使用 stdio.h.
她们仅仅是定义。
------解决思路----------------------
那个标准不是说的很清楚吗? 就是说,标准本身是假定你没有stdio.h中规定的i/o需求的。而现在你有读写文件的需求,因此,需要你的嵌入式系统支持你读写文件这类操作。对于标准情况而言,这类操作可能包含大量为定义的行为,因此,至于如何使用,只有从你的系统本身那里找答案。
ps:提示一下,怎么读写文件要看你的文件系统接口,如果你的系统里根本没有文件系统,那么就不能读写文件。