Share via


_getchar_nolock_getwchar_nolock

從標準輸入讀取字元,且不需要鎖定。

語法

int _getchar_nolock( void );
wint_t _getwchar_nolock( void );

傳回值

請參閱:getchargetwchar

備註

_getchar_nolock_getwchar_nolock 就相當於 getchargetwchar,不同之處在於未受保護,因此會受到其他執行緒的干擾。 因為其不會造成鎖定其他執行緒的額外負荷,所以可能會比較快。 這些函式只能用在安全執行緒內容 (例如單一執行緒應用程式) 或呼叫範圍已經處理執行緒隔離的地方。

一般文字常式對應

Tchar.h 常式 _UNICODE_MBCS 未定義 _MBCS 已定義 _UNICODE 已定義
_gettchar_nolock _getchar_nolock _getchar_nolock _getwchar_nolock

需求

常式 必要的標頭
_getchar_nolock <stdio.h>
_getwchar_nolock <stdio.h> 或 <wchar.h>

通用 Windows 平台 (UWP) 應用程式中不支援主控台。 與主控台 stdinstdoutstderr 相關聯的標準資料流控制代碼必須重新導向,之後 C 執行階段函式才能在 UWP 應用程式中使用它們。 如需相容性詳細資訊,請參閱相容性

範例

// crt_getchar_nolock.c
// Use _getchar_nolock to read a line from stdin.

#include <stdio.h>

int main()
{
    char buffer[81];
    int i, ch;

    for (i = 0; (i < 80) && ((ch = _getchar_nolock()) != EOF)
                         && (ch != '\n'); i++)
    {
        buffer[i] = (char) ch;
    }

    // Terminate string with a null character

    buffer[i] = '\0';
    printf( "Input was: %s\n", buffer);
}

This textInput was: This text

另請參閱

資料流 I/O
getc, getwc
fgetcfgetwc
_getch_getwch
putcputwc
ungetc, ungetwc