fprintf() - I/O Function

How is "fprintf()" used in C++?


fprint() is an I/O function that is used to output the values of arguments given after the "format" string in the specified format.


int fprintf( FILE * stream, const char *format,...);

The following table lists the type specifier used with fprintf()
Type Description
c Character
d or i Signed decimal integer
e Scientific notation using e character
E Scientific notation using E character
f Decimal floating point
g Use the shorter of %e or %f
G Use the shorter of %E or %f
o Signed octal
s String of characters
u Unsigned decimal integer
x Unsigned hexadecimal integer
X Unsigned hexadecimal integer(capital)
p Pointer address
% A % followed by another % character will write % to the stream.

Example :

#include <stdio.h>
int main()
char a[] = "India";
FILE *str = fopen( "fprintfeg.txt", "w" );
fprintf( str, "Hiox %s\n", a );


Hiox India

In the above example the "fprintf()" is used to print the output "Hiox India" to the file "fprintfeg.txt".

C++ Tutorial

Ask Questions

Ask Question