fprintf中,printf和sprintf的区别? [英] Difference between fprintf, printf and sprintf?

查看:176
本文介绍了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.

这篇关于fprintf中,printf和sprintf的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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