How to read a .gz file line-by-line in C++?

后端 未结 7 509
一整个雨季
一整个雨季 2020-12-29 23:08

I have 3 terabyte .gz file and want to read its uncompressed content line-by-line in a C++ program. As the file is quite huge, I want to avoid loading it completely in memor

7条回答
  •  轮回少年
    2020-12-29 23:28

    For something that is going to be used regularly, you probably want to use one of the previous suggestions. Alternatively, you can do

    gzcat file.gz | yourprogram
    

    and have yourprogram read from cin. This will decompress parts of the file in memory as it is needed, and send the uncompressed output to yourprogram.

提交回复
热议问题