fprintf中,printf和sprintf的区别?
任何人都可以用简单的英语约fprintf中之间的的printf
,的差异解释了,
的sprintf
举例?
Can anyone explain in simple English about the differences between printf
, fprintf
, and sprintf
with examples?
什么流是它?
我是这三个之间真的很困惑一边念叨文件用C处理。
I'm really confused between the three of these while reading about "File Handling in C".
在C,一个流是一个抽象概念;从程序的角度来看,这简直就是个字节的生产者(输入流)或消费者(输出流)。它可以对应于磁盘上的文件,以一个管道,到终端或一些其它装置如打印机或终端。在文件
类型包含的流的信息。通常情况下,你不要乱用文件
对象的内容直接,你只是一个指针传递给它的各种I / O例程。
In C, a "stream" is an abstraction; from the program's perspective it is simply a producer (input stream) or consumer (output stream) of bytes. It can correspond to a file on disk, to a pipe, to your terminal, or to some other device such as a printer or tty. The FILE
type contains information about the stream. Normally, you don't mess with a FILE
object's contents directly, you just pass a pointer to it to the various I/O routines.
有三种标准流:标准输入
是指向标准输入流,标准输出
是一个指向标准输出流,而标准错误
是指向标准错误输出流。在互动环节,这三个通常是指到控制台,虽然你可以重定向它们指向其他文件或设备:
There are three standard streams: stdin
is a pointer to the standard input stream, stdout
is a pointer to the standard output stream, and stderr
is a pointer to the standard error output stream. In an interactive session, the three usually refer to your console, although you can redirect them to point to other files or devices:
$ myprog < inputfile.dat > output.txt 2> errors.txt
在这个例子中,标准输入
现在指向 inputfile.dat
,标准输出
点 output.txt的
和标准错误
点 ERRORS.TXT
。
In this example, stdin
now points to inputfile.dat
, stdout
points to output.txt
, and stderr
points to errors.txt
.
fprintf中
写格式的文本到指定的输出流。
fprintf
writes formatted text to the output stream you specify.
的printf
等同于写 fprintf中(标准输出,...)
,并写入格式化文本到任何地方标准输出流当前指向。
printf
is equivalent to writing fprintf(stdout, ...)
and writes formatted text to wherever the standard output stream is currently pointing.
的sprintf
写入格式化的文本字符
的数组,而不是流。
sprintf
writes formatted text to an array of char
, as opposed to a stream.