wint_t ungetwc(wint_t wChar, FILE* qpStream);
#include <cwchar> #include <cstdio> int main() { using namespace std; char* cpFileName = "XoaX.txt"; FILE* qpFile = fopen(cpFileName, "r"); // Check that the file could be opened if (!qpFile) { wprintf(L"Could not open file.\n"); return 1; } // Read 8 chars from the file for (int iIndex = 0; iIndex < 8; ++iIndex) { int iReturn = getwc(qpFile); wprintf(L"%wc", (wchar_t)iReturn); } wprintf(L"\n"); // Put 4 Ts back into the stream for (int iIndex = 0; iIndex < 4; ++iIndex) { wchar_t wChar = L'T'; int iReturn = ungetwc(wChar, qpFile); wprintf(L"%wc", (wchar_t)iReturn); } wprintf(L"\n"); // Read 10 chars from the file for (int iIndex = 0; iIndex < 10; ++iIndex) { int iReturn = getwc(qpFile); wprintf(L"%wc", (wchar_t)iReturn); } wprintf(L"\n"); fclose(qpFile); // Keep the window open until "Enter" is pressed getwchar(); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.