"test %d %d 255/r" tells that after it will be arguments (and they are there: 255, 255) and they are expected to be of integer type. And they will be placed instead of %d.
In result you'll get string test 255 255 255 in your file.
The first parameter is a file handle, the second is a formatting string, and after that there is a variable number of arguments depending on how many format specifiers you used in your 2nd parameter.
Check the documentation, it contains all of the information you are asking.
it's a formatted output to a file stream. It works like printf does, the difference is that printf always outputs to stdout.If you wrote
fprintf(stdout, "test %d %d 255\n", 255, 255);
it would be the same as the printf equivalent.
The second argument to it is the format string. The format string contains format specifiers, like %s, %d, %x. Yours contains two %ds. Each format specifier must have a corresponding argument in fprintf. Yours has two %d specifiers, so there are two numerical arguments:
fprintf(outfile, "Here are two numbers: %d, %d", 4, 5);
likewise, you could use string specifiers (%s), hexadecimal specifiers (%x) or long/long long int specifiers (%ld, %lld). Here is a list of them: http://www.cppreference.com/wiki/c/io/printf. Note that they are the same for all of the C formatted i/o functions (like sprintf and scanf).
Also, in your original example, "/r" will just literally print "/r". It looks like you were trying to do a carriage return ("\r").
The second argument is the format string. Any additional arguments are the parameters to the specifier in the format string (in this case, %d). Check out http://www.cppreference.com/wiki/c/io/printf for a good intro to printf-style functions.
发布评论
评论(5)
"test %d %d 255/r"
告诉后面将是参数(它们在那里:255, 255)并且它们应该是整数类型。并且它们将代替 %d 被放置。结果,您将在文件中获得字符串
test 255 255 255
。有关更多信息,请阅读
std::fprintf
参考。"test %d %d 255/r"
tells that after it will be arguments (and they are there: 255, 255) and they are expected to be of integer type. And they will be placed instead of %d.In result you'll get string
test 255 255 255
in your file.For more infrormation read
std::fprintf
reference.第一个参数是文件句柄,第二个参数是格式化字符串,之后的参数数量可变,具体取决于第二个参数中使用的格式说明符的数量。
检查文档,它包含您询问的所有信息。
The first parameter is a file handle, the second is a formatting string, and after that there is a variable number of arguments depending on how many format specifiers you used in your 2nd parameter.
Check the documentation, it contains all of the information you are asking.
它是文件流的格式化输出。它的工作方式与 printf 类似,不同之处在于 printf 始终输出到 stdout。如果您编写
它,它将与 printf 等效项相同。
它的第二个参数是格式字符串。格式字符串包含格式说明符,例如
%s
、%d
、%x
。您的包含两个%d
。每个格式说明符必须在fprintf
中具有相应的参数。您的有两个%d
说明符,因此有两个数字参数:同样,您可以使用字符串说明符 (
%s
)、十六进制说明符 (%x)或 long/long long int 说明符(
%ld
、%lld
)。以下是其中的列表: http://www.cppreference.com/wiki/c /io/printf。请注意,它们对于所有 C 格式的 I/O 函数(如 sprintf 和 scanf)都是相同的。另外,在您原来的示例中,“
/r
”将直接打印“/r
”。看起来您正在尝试执行回车符(“\r
”)。it's a formatted output to a file stream. It works like printf does, the difference is that printf always outputs to stdout.If you wrote
it would be the same as the
printf
equivalent.The second argument to it is the format string. The format string contains format specifiers, like
%s
,%d
,%x
. Yours contains two%d
s. Each format specifier must have a corresponding argument infprintf
. Yours has two%d
specifiers, so there are two numerical arguments:likewise, you could use string specifiers (
%s
), hexadecimal specifiers (%x
) or long/long long int specifiers (%ld
,%lld
). Here is a list of them: http://www.cppreference.com/wiki/c/io/printf. Note that they are the same for all of the C formatted i/o functions (like sprintf and scanf).Also, in your original example, "
/r
" will just literally print "/r
". It looks like you were trying to do a carriage return ("\r
").它类似于 printf,它只是将输出打印到文件中。
It's similar to printf, it just prints the output to a file.
第二个参数是格式字符串。任何附加参数都是格式字符串中说明符的参数(在本例中为 %d)。查看 http://www.cppreference.com/wiki/c/io/printf< /a> 很好地介绍了 printf 风格的函数。
The second argument is the format string. Any additional arguments are the parameters to the specifier in the format string (in this case, %d). Check out http://www.cppreference.com/wiki/c/io/printf for a good intro to printf-style functions.