C Standard Libraries C++



wint_t fgetwc(FILE* qpStream);


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


#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;

    return 0;


fgetwc() Output

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