C Standard Libraries C++

fgetwc()

Declaration

wint_t fgetwc(FILE* qpStream);

Description

This function reads in a single character from "qpStream" and returns its value as a wide character. If the read was successful, the character that was read is returned as a wide character. Otherwise, the function returns WEOF to indicate an error.

Input File

fgetwc() Input File

Example

#include <iostream>
#include <cwchar>

int main()
{
    using namespace std;
    char* cpFileName = "XoaX.txt";
    FILE* qpFile = fopen(cpFileName, "r");

    // Check that the file could be opened
    if (!qpFile) {
        wcout << L"Could not open the file" << endl;
        return 1;
    }

    // Read the first char of the file.
    wchar_t wFirstChar = fgetwc(qpFile);
    if (wFirstChar != WEOF) {
        // Output it as a char.
        wcout << L"Char read: " << wFirstChar << endl;
    } else {
        wcout << L"Read Error" << endl;
    }
    fclose(qpFile);

    return 0;
}

Output

fgetwc() Output
 

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