是否有一个标准函数可以打印/监视stdin文件的内容,同时将数据留在stdin中
Is there a standard-function which prints out/monitor the content of the stdin file while leaving the data inside stdin?
标准库是否提供了一种更快的替代方案,只需读取stdin
文件的所有内容/任何字符,将所有字符写入一个数组,然后将整个数组的内容分别交给stdout
和stdin
(因为其仅用于"分析"目的(?
我只想简单地分析stdin
文件中的实际内容,而不是从中获取数据。
我找不到标准库的任何函数,它可以做到这一点。
我知道这很少,但我想我想要什么已经没有什么好说的了。
问题是针对C和C++的,因为我同时使用这两种语言。如果这两种语言之间的答案发生了变化,请说明重点是哪种语言。
您可以使用getchar按字符形式stdin
读取字符。然而,在许多情况下,使用缓冲区(例如字符数组(会更快。
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int ch;
while ((ch=getchar()) != EOF) /* read/print "abcde" from stdin */
printf("%c", ch);
/* Test reason for reaching EOF. */
if (feof(stdin)) /* if failure caused by end-of-file condition */
puts("End of file reached");
else if (ferror(stdin)) /* if failure caused by some other error */
{
perror("getchar()");
fprintf(stderr,"getchar() failed in file %s at line # %dn", __FILE__,__LINE__-9);
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
相关文章:
- 防止主数据类型C++的隐式转换
- 用于访问容器<T>数据成员的正确 API
- 嵌套在类中时无法设置成员数据
- 使用流处理接收到的数据
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在cuda线程之间共享大量常量数据
- C++将文本文件中的数据读取到结构数组中
- 如何在C++中序列化结构数据
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 是否有一个标准函数可以打印/监视stdin文件的内容,同时将数据留在stdin中
- c - 函数选择显示读取后stdin中有数据
- 如何将数据写入 stdin,以便由等待来自 stdin 输入的单独线程使用?
- C++:在数据写入管道时从 stdin 读取
- 如何从 stdin(对于 C++ 中给定数量的测试用例)读取数据
- 如何使用C++通过stdin获取可用数据的大小:当stdin未重定向时
- 如果从文件流中读取数据,gSOAP为什么将stdin模式设置为二进制
- 通过stdin和ostream向程序发送数据.(C++)
- 仅重定向子进程stdin,并从stdout和stderr中删除数据
- 如何使用C++通过stdin获取可用数据的大小