C Standard Libraries C++

vfprintf()

Declaration

int vfprintf(FILE* qpStream, const char* kcpFormatString, va_list qVarArgList);

Description

This function writes the formatted string "kcpFormatString" to the stream given by "qpStream," using the arguments in the argument list "qVarArgList." The function returns the number of characters that were written to the stream, or returns a negative number to indicate that an error occurred.

Input File

vfprintf() Input File

Output File

vfprintf() Output File

Example

#include <cstdio>
#include <cstdarg>

int main()
{
    char* cpFileName = "XoaX.txt";
    // Open an ASCII text file for appending.
    FILE* qpFile = fopen(cpFileName, "a");

    // Check that the file was opened successfully.
    if (!qpFile) {
        printf("Could not open the file %s\n",  cpFileName);
        return 1;
    }

    // An argument list - the first entry is just a count.
    int iaArguments[] = {2, 10, 20};
    va_list qVarArg = 0;
    va_start(qVarArg, iaArguments[0]);

    // Use a var arg list to output two integers
    vfprintf(qpFile, "\n%d %d", qVarArg);

    va_end(qVarArg);

    fclose(qpFile);
    return 0;
}

Output

vfprintf() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.