首先是簡單文件,使用fstream中的方法。
///read_file.cpp
#include
#include
#include
using namespace std;
int main()
{
ifstream input_file;
ofstream output_file;
input_file.open("/home/lisp/c++/hello.cpp");
string str;
input_file>>str;
cout<
.gz壓縮文件,需要安裝zlib庫,使用庫中的方法將壓縮文件讀入。
///read_zip_file.cpp
#include
#include
#include
using namespace std;
///buffer size
const int GZ_BUF_SIZE = 1024;
int main(int argc, char** argv)
{
///read gz filename from command argv[1]
gzFile file = gzopen(argv[1],"rb");
unsigned char buf[GZ_BUF_SIZE];
int len;
string out;
while (len = gzread(file, buf, GZ_BUF_SIZE))
{
out.append((const char*)buf, len);
}
///close the file
gzclose(file);
cout<
關於其他壓縮格式的文件以後在繼續學習。