我试图stdin在运行时读取一个大型二进制文件思想输入重定向(),并且stdin是必需的.
./a.out < input.bin
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经使用了fgets.但是fgets会跳过空白和换行.我想包括两者.我currentBuffersize可以动态变化.
FILE * inputFileStream = stdin;
int currentPos = INIT_BUFFER_SIZE;
int currentBufferSize = 24; // opt
unsigned short int count = 0; // As Max number of packets 30,000/65,536
while (!feof(inputFileStream)) {
char buf[INIT_BUFFER_SIZE]; // size of byte
fgets(buf, sizeof(buf), inputFileStream);
cout<<buf;
cout<<endl;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.