0

I can read file in c++. This is my code:

std::string ReadFile(std::string file)
{
    char buff[20480];
    std::ifstream fread(file, std::ios::binary | std::ios::app);
    fread.read(buff,sizeof(buff));
    std::string str = buff;
    fread.close();
    return str;
}

The variable "file" is the FilePath. And I get a folder .zip, I want to read the file in folder. What should I do? I try to use libzip, but it can't solve my problem, maybe I didn't use it by wrong way.

Nicholas
  • 94
  • 11

3 Answers3

1

No. To unzip a file, you must unzip a file.

You don't need to invoke the unzip utility to do it: there are libraries that can expose decompression through a streams API, resulting in code that looks rather similar to what you've written above. But you need to install and learn how to use those libraries.

Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021
0

Unless you have access to the API that allows to unpack your file I don't see how directly in the code. If you are lazy you could write a small script in whatever language you prefer that does the unpacking and then calls your program on the unpacked file

Triskeldeian
  • 560
  • 3
  • 15
0

Assuming, you have unzip available. Did you try something like:

FILE * file = popen("unzip -p filename", "r");

Similarly, popen("gzip -f filename", "r") should work for gzip.

In order to parse the output, I'd refer to this post (with Windows hints). I don't know about a more C++-style way of doing this.

Community
  • 1
  • 1
m8mble
  • 1,413
  • 1
  • 18
  • 28