小编Jer*_*rry的帖子

通过输入重定向读取二进制文件c ++的最佳方法

我试图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)

提前致谢.

c++ stdin stream cin

3
推荐指数
1
解决办法
1842
查看次数

标签 统计

c++ ×1

cin ×1

stdin ×1

stream ×1