|
|
Tutorials

Cpp

|
Topic |
How is "fprintf()" used in C++?
|
|
Explanation |
|
fprint() is an I/O function that is used to output the values of arguments given after the "format"
string in the specified format.
Syntax:
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 );
}
|
Result:fprintfeg.txt
Hiox India
In the above example the "fprintf()" is used to print the output "Hiox India" to the
file "fprintfeg.txt".
|
| Note |
C++ is one of the most used programming languages in the world. Also known as "C with Classes".
Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.
|
|
|
|