_getc_nolock
,_getwc_nolock
读取流中的字符,而不进行锁定。
语法
int _getc_nolock(
FILE *stream
);
wint_t _getwc_nolock(
FILE *stream
);
参数
stream
输入流。
返回值
请参阅 getc
、getwc
。
备注
这些函数与 getc
和 getwc
相同,只不过前者不锁定调用线程。 它们可能更快,因为它们不会产生锁定其他线程的开销。 仅在线程安全的上下文中使用这些函数,如单线程应用程序或调用范围已经处理线程隔离。
默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态。
一般文本例程映射
Tchar.h 例程 | _UNICODE 和 _MBCS 未定义 |
_MBCS 已定义 |
_UNICODE 已定义 |
---|---|---|---|
_gettc_nolock |
getc_nolock |
getc_nolock |
getwc_nolock |
要求
例程 | 必需的标头 |
---|---|
getc_nolock |
<stdio.h> |
getwc_nolock |
<stdio.h> 或 <wchar.h> |
有关兼容性的详细信息,请参阅 兼容性。
示例
// crt_getc_nolock.c
// Use getc to read a line from a file.
#include <stdio.h>
int main()
{
char buffer[81];
int i, ch;
FILE* fp;
// Read a single line from the file "crt_getc_nolock.txt".
fopen_s(&fp, "crt_getc_nolock.txt", "r");
if (!fp)
{
printf("Failed to open file crt_getc_nolock.txt.\n");
exit(1);
}
for (i = 0; (i < 80) && ((ch = getc(fp)) != EOF)
&& (ch != '\n'); i++)
{
buffer[i] = (char) ch;
}
// Terminate string with a null character
buffer[i] = '\0';
printf( "Input was: %s\n", buffer);
fclose(fp);
}
输入:crt_getc_nolock.txt
Line the first.
Line the second.
输出
Input was: Line the first.
另请参阅
流 I/O
fgetc
, fgetwc
_getch
、_getwch
putc
、putwc
ungetc
、ungetwc
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈