C++ 如何在C+;中一次性扫描STDIN中的100个字节+;

C++ 如何在C+;中一次性扫描STDIN中的100个字节+;,c++,string,io,inputstream,C++,String,Io,Inputstream,扫描仪等待我们输入100字节的数据。因此,如果我们将文件重定向到 如果文件的数据大于100字节,则为可执行文件的输入。我一次扫描它,而不是使用fgets()或scanf(“%s”)等逐行扫描。您可以使用fread读取所需的字节数,而不受换行符或其他空格的影响: char buf[100]; size_t bytes_read = fread(buf, 1, 100, stdin); 请注意,buf将不会以null结尾。因此,如果您想printfit,例如(它需要一个以null结尾的字符串),您

扫描仪等待我们输入100字节的数据。因此,如果我们将文件重定向到
如果文件的数据大于100字节,则为可执行文件的输入。我一次扫描它,而不是使用
fgets()
scanf(“%s”)
等逐行扫描。

您可以使用
fread
读取所需的字节数,而不受换行符或其他空格的影响:

char buf[100];
size_t bytes_read = fread(buf, 1, 100, stdin);
请注意,
buf
将不会以null结尾。因此,如果您想
printf
it,例如(它需要一个以null结尾的字符串),您可以尝试以下操作:

char buf[101];
size_t bytes_read = fread(buf, 1, 100, stdin);
buf[100] = '\0'; // The 101th "cell" of buf will be
                 // the one at index `100` since the
                 // first one is at index `0`.

您可以使用
fread
读取所需的字节数,与换行符或其他空格无关:

char buf[100];
size_t bytes_read = fread(buf, 1, 100, stdin);
请注意,
buf
将不会以null结尾。因此,如果您想
printf
it,例如(它需要一个以null结尾的字符串),您可以尝试以下操作:

char buf[101];
size_t bytes_read = fread(buf, 1, 100, stdin);
buf[100] = '\0'; // The 101th "cell" of buf will be
                 // the one at index `100` since the
                 // first one is at index `0`.
fread()是您要查找的函数。相关:相关:fread()是您要查找的函数。相关:相关: