是否有任何人用简单的英文解释f
、fprintf
和sprintf
之间的差别?
它的底线是什么?
我确实混淆了其中三个部分,同时阅读了“C中的易碎处理”。
是否有任何人用简单的英文解释f
、fprintf
和sprintf
之间的差别?
它的底线是什么?
我确实混淆了其中三个部分,同时阅读了“C中的易碎处理”。
在C,一种“上游”是一种抽象的概念;从方案角度看,它只是一种 by的生产者(投入流)或消费者(产出流)。 它可与磁盘、管道、终端或印刷机等其他一些装置相对应。 <代码>FILE 类型载有有关溪流的信息。 通常,你没有带<条码>的密码。 直接反对内容,你只是向各种I/O例行公事发过问。
三个标准流:st
是标准投入流的指点,stdout
是标准产出流的指点,stderr
是标准错误产出流的指点。 在一次互动会议上,这三人通常指的是你的独角,尽管你可以将其转移到其他档案或装置上:
$ myprog < inputfile.dat > output.txt 2> errors.txt
例如,stdin
现有<代码>inputfile.dat ,stdout
points to output.txt
, and stder
points to
<代码>fprintf向产出流书写格式案文,请具体说明。
<代码>f相当于写作fprintf(stdout, ......)
,并在标准产出流目前点的任何地方书写格式案文。
http://www.ohchr.org。
FILE*
)
char*
)
printf(const char *format, ...)
is used to print the data onto the standard output which is often a computer monitor.sprintf(char *str, const char *format, ...)
is like printf
. Instead of displaying the formated string on the standard output i.e. a monitor, it stores the formated data in a string pointed to by the char pointer (the very first parameter). The string location is the only difference between printf and sprint syntax.fprintf(FILE *stream, const char *format, ...)
is like printf
again. Here, instead of displaying the data on the monitor, or saving it in some string, the formatted data is saved on a file which is pointed to by the file pointer which is used as the first parameter to fprintf
. The file pointer is the only addition to the syntax of printf
.如果stdout
file is used as the first para amount in fprintf
,则其工作应视为等同于printf
。
<代码>fprintf用于输出。
http://www.ohchr.org。
注还有<代码>vsprintf,vfprintf
和vprintf
。
You( v)的功能也非常有用:
$ cat test.cc
#include <exception>
#include <stdarg.h>
#include <stdio.h>
struct exception_fmt : std::exception
{
exception_fmt(char const* fmt, ...) __attribute__ ((format(printf,2,3)));
char const* what() const throw() { return msg_; }
char msg_[0x800];
};
exception_fmt::exception_fmt(char const* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsnprintf(msg_, sizeof msg_, fmt, ap);
va_end(ap);
}
int main(int ac, char** av)
{
throw exception_fmt("%s: bad number of arguments %d", *av, ac);
}
$ g++ -Wall -o test test.cc
$ ./test
terminate called after throwing an instance of exception_fmt
what(): ./test: bad number of arguments 1
Aborted (core dumped)
印刷
印刷("control string ", argument );
f印刷
f印刷 (filename, "control string ", argument );
印本:书写格式数据,以显示记忆而不是out缩。
print的协同效应是:
#include <stdio.h>
int sprintf (char *string, const char *format
[,item [,item]…]);
Here,
努力指点人,在数据要书写时,应保持缓冲。
格式是指说明格式的特性。
每个项目都是一个变数或表示,具体列明数据。
如果业务成功,或换言之,书面的特性数目,不计取消无效性质,如果发生错误,则以印本退还的价值大于或等于零。
印刷:印刷
印刷税:
printf format [argument]…
印本和印刷法之间的唯一区别是,印本()将数据写成一个特性阵列,而印刷法()则撰写数据,用于淘汰标准产出装置。
其他人已经作了详细解释;我的发言仅以非常基本的例子对关于<条码><>>>/条码>和<条码>的实用讨论作出回答。
附录一 具体来说,你希望:(一) 在你的屏幕上印刷这一版本,(二)在变数中加以节省,供今后使用。 可在(一)和<条码>(二)中使用<条码>。 这里是法典。
/* saves file name and current line in a string and prints it on the screen*/
#include <stdio.h>
int main(void) {
/* note the use of a marco to save the line nr. */
int line_n= __LINE__;
/* note the use of a marco to save the file name */
char file_name[]= __FILE__;
/* Some text you wish to print/save */
char line[] = "Line ";
char file[]= " of file ";
char my_str[100];
/* expand everything and save it in my_str for future use */
sprintf(my_str, "%s%d%s%s", line, line_n, file, file_name);
/* or just print it out on the screen */
printf("%s", my_str);
return 0;
}
For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...
最好、最小、最快、开放的来源、C/C++ 3d 提供方(在3ds max模型的支持下),而不是通用公平市价,
Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...
I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...
I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...
I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...
Is there anything other than DDD that will draw diagrams of my data structures like DDD does that runs on Linux? ddd is okay and runs, just kind of has an old klunky feeling to it, just wanted to ...
Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...