简体   繁体   中英

how do I decompress tar.gz file using c++ program

In my linux program, I want to decompress a tar.gz file contents to a specific directory. Is there any system call or any C++ class available in C/C++ to extract file contents from tar.gz file?

There is excellent library libarchive , which supports accessing multiple archive formats using consistent API. You can follow these examples on how to use it.

If you are on Ubuntu, you can easily install this library using command sudo apt-get install libarchive-dev . On other platforms, you may need to download source code and compile this library yourself.

One advantage of using libarchive vs. using system() calls is not depending on system utilities, and also it should work faster because it does not fork.

http://www.cplusplus.com/reference/cstdlib/system/

You can do it like this:

   system("tar -zxvf yourfile");

You may see this too:

如果包含<cstdlib> ,则可以调用:

system("your tar or gz command");

You can use several libs like libtar.

Or you can use a system call like you already mentioned:

system("tar -zxf /your/file.tar.gz")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM