如何在使用boost::bzip2_decompressor()时摆脱额外的值
how to get rid of extra values while using boost::bzip2_decompressor()
我有一个txt文件:gcc-4.7.2.txt:与数据写入:你好,这是一个测试文件。谢谢:压缩为gcc-4.7.2.tar.bz2
现在,我运行以下代码:#include <sstream>
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/filesystem.hpp>
int main()
{
using namespace std;
using namespace boost::iostreams;
char filename[] = "gcc-4.7.2.tar.bz2";
if (!boost::filesystem::exists(filename))
{
cout << "Can't find " << filename << ". Expect errors to follow! " << endl;
}
ifstream file(filename, ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
filtering_streambuf<output> out;
in.push(bzip2_decompressor());
in.push(file);
try
{
//cout << "in_file:" << in << endl;
boost::iostreams::copy(in, cout);
//boost::iostreams::copy(in, out);
//cout << cout << endl;
//boost::iostreams::copy(in, compressed_string);
//cout << "Copied" << compressed_string << " " << in.str() << endl;
}
catch (const bzip2_error& exception)
{
cout << "catchblock" << endl;
cout << exception.what() << endl;
int error = exception.error();
if (error == bzip2::data_error)
{
cout << "compressed data stream is corrupted";
}
else if (error == bzip2::data_error_magic)
{
cout << "compressed data stream does not begin with the 'magic' sequence 'B' 'Z' 'h'";
}
else if (error == bzip2::config_error)
{
cout << "libbzip2 has been improperly configured for the current platform";
}
else
{
cout << "Error: " << error;
}
cout << endl;
}
}
运行时输出如下:
dev4@sun-desktop: ~/readerwriter美元。/test1gcc-4.7.2。txt0000644000175100001440000000004312547435102011603 0ustar dev4userhello这是一个测试文件。
感谢Hello之前的字符是什么?为什么要打印文件名?
如何去掉那些额外的值。并且只打印文件的内容:
你好这是一个测试文件。
谢谢
不能。
这些不是"额外值"。
-
如果你不想要tar文件,就不要使用tar文件。
使用
bzip2
来压缩单个文件 -
如果输入是tar存档文件,使用
tar
提取。Boost does not支持tar存档
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::asio::steady_timer()与sleep()我应该使用哪一个
- boost::asio如何生成多个协同程序,然后加入它们
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 使用Boost Interprocess创建托管共享内存需要很长时间
- Boost::posix_time::ptime舍入到给定的分钟数
- boost xml parsingl将xml的路径作为变量发送