C Standard Libraries C++

getwc()

Declaration

wint_t getwc(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

getwc() 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) {
        cout << "Could not open the file!" << endl;
        return 1;
    }

    // Read a char from the file
    int iReturn = getwc(qpFile);
    // Check whether the read was successful.
    if (iReturn == WEOF) {
        cout << "Read error!" << endl;
    } else {
        wcout << "Read char = " << (wchar_t)iReturn << endl;
    }
    fclose(qpFile);
    return 0;
}

Output

getwc() Output
 

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