练习写C++代码(101)--简单的文件以及 .gz文件的读写
2014-05-03 22:22
537 查看
首先是简单文件,使用fstream中的方法。
.gz压缩文件,需要安装zlib库,使用库中的方法将压缩文件读入。
关于其他压缩格式的文件以后在继续学习。
///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<
关于其他压缩格式的文件以后在继续学习。
相关文章推荐
- 代码练习 简单文件读写 字符串 数组的处理 list Dictionary
- C++ 读写文件,格式化输出到文件的简单代码
- C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组
- C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组
- 读写plist文件简单代码
- c++中 vs 简单的对txt文件读写
- SequenceInputStream类的简单介绍。以及用该类合并集合文件数据的程序代码。
- C++自动创建命名的txt文件以及读写txt文件
- 最简单的plist文件读写代码
- C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组
- C++文件读写代码分享
- struts2下载文件原理以及简单下载代码
- C/C++读写文件时莫忘了设置区域代码
- C++二进制文件读写简单操作
- C++ 读写大文件代码
- 【代码备忘】C++ fstream 读写 unicode 文件
- 简单C++文件读写例子
- 练习写C++代码(10)--实现简单的时钟类2
- C++ 输出代码所在的文件、行数以及函数名称
- C++ 结合 Boost:40行代码读写和处理 txt 文件