- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
int main()
{
using namespace std;
using namespace boost::iostreams;
ifstream file("gcc-4.7.2.tar.bz2", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(bzip2_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
system("pause");
return 0;
}
我已经按照这个问题安装了 Boost: How to use Boost in Visual Studio 2010 ?
我在 boost::iostreams::copy(in, cout)
语句中出错。
我是 Boost 的新手,所以我不知道这段代码是对还是错。
我想我做了所有我应该做的事,但我迷路了。
编辑
我检查了这个问题:exceptions from boost::iostreams::copy() .
而且我已经更改了我的测试代码以了解我得到了什么错误。
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
int main()
{
using namespace std;
using namespace boost::iostreams;
try {
ifstream file("hello.bz2", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(bzip2_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
}
catch(const bzip2_error& exception) {
int error = exception.error();
if(error == boost::iostreams::bzip2::data_error) {
// compressed data stream is corrupted
cout << "compressed data stream is corrupted";
}
else if(error == boost::iostreams::bzip2::data_error_magic)
{
// compressed data stream does not begin with the 'magic' sequence 'B' 'Z' 'h'
cout << "compressed data stream does not begin with the 'magic' sequence 'B' 'Z' 'h'";
}
else if(boost::iostreams::bzip2::config_error) {
// libbzip2 has been improperly configured for the current platform
cout << "libbzip2 has been improperly configured for the current platform";
}
}
}
它说我得到 boost::iostreams::bzip2::config_error
。
这是否意味着我安装了错误的 bzip2 过滤器???
因为我在使用时遇到了一些错误
b2 --toolset=msvc-10.0 -sBZIP2_SOURCE="C:\bzip2-1.0.6" --build-type=complete stage
我得到:
C:\boost_1_54_0>b2 --toolset=msvc-10.0 -sBZIP2_SOURCE="C:\bzip2-1.0.6" --build-t
ype=complete stage
Performing configuration checks
- 32-bit : yes (cached)
- arm : no (cached)
- mips1 : no (cached)
- power : no (cached)
- sparc : no (cached)
- x86 : yes (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <thre
ading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <th
reading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- has_icu builds : no (cached)
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
- zlib : no (cached)
- iconv (libc) : no (cached)
- iconv (separate) : no (cached)
- icu : no (cached)
- icu (lib64) : no (cached)
- message-compiler : yes (cached)
- compiler-supports-ssse3 : yes (cached)
- compiler-supports-avx2 : no (cached)
- gcc visibility : no (cached)
- long double support : yes (cached)
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
warning: No python installation configured and autoconfiguration
note: failed. See http://www.boost.org/libs/python/doc/building.html
note: for configuration instructions or pass --without-python to
note: suppress this message and silently skip all Boost.Python targets
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <thre
ading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <th
reading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <thre
ading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <th
reading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <thre
ading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <th
reading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
- zlib : no (cached)
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <thre
ading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <th
reading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <thre
ading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <th
reading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
- zlib : no (cached)
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <thre
ading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <th
reading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <thre
ading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <th
reading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
Component configuration:
- atomic : building
- chrono : building
- context : building
- coroutine : building
- date_time : building
- exception : building
- filesystem : building
- graph : building
- graph_parallel : building
- iostreams : building
- locale : building
- log : building
- math : building
- mpi : building
- program_options : building
- python : building
- random : building
- regex : building
- serialization : building
- signals : building
- system : building
- test : building
- thread : building
- timer : building
- wave : building
...patience...
...patience...
...patience...
...patience...
...patience...
...found 47439 targets...
C:\boost_1_54_0>b2 --toolset=msvc-10.0 -sBZIP2_SOURCE="C:\bzip2-1.0.6" --build-type=complete stage
Performing configuration checks
- 32-bit : yes (cached)
- arm : no (cached)
- mips1 : no (cached)
- power : no (cached)
- sparc : no (cached)
- x86 : yes (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <threading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <threading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- has_icu builds : no (cached)
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
- zlib : no (cached)
- iconv (libc) : no (cached)
- iconv (separate) : no (cached)
- icu : no (cached)
- icu (lib64) : no (cached)
- message-compiler : yes (cached)
- compiler-supports-ssse3 : yes (cached)
- compiler-supports-avx2 : no (cached)
- gcc visibility : no (cached)
- long double support : yes (cached)
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
warning: No python installation configured and autoconfiguration
note: failed. See http://www.boost.org/libs/python/doc/building.html
note: for configuration instructions or pass --without-python to
note: suppress this message and silently skip all Boost.Python targets
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <threading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <threading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <threading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <threading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <threading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <threading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
- zlib : no (cached)
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <threading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <threading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <threading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <threading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
- zlib : no (cached)
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <threading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <threading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
error: No best alternative for libs/coroutine/build/allocator_sources
next alternative: required properties: <link>static <target-os>windows <threading>multi
not matched
next alternative: required properties: <link>static <segmented-stacks>on <threading>multi
not matched
next alternative: required properties: <link>static <threading>multi
not matched
- zlib : no (cached)
Component configuration:
- atomic : building
- chrono : building
- context : building
- coroutine : building
- date_time : building
- exception : building
- filesystem : building
- graph : building
- graph_parallel : building
- iostreams : building
- locale : building
- log : building
- math : building
- mpi : building
- program_options : building
- python : building
- random : building
- regex : building
- serialization : building
- signals : building
- system : building
- test : building
- thread : building
- timer : building
- wave : building
...patience...
...patience...
...patience...
...patience...
...patience...
...found 47439 targets...
最佳答案
您收到的错误实际上具有误导性。
这是因为:
if(boost::iostreams::bzip2::config_error)
...总是评估为非零并给你错误的错误信息!
我没有可用的 Windows PC,但我在 Mac 上测试了“您的”代码(使用 Homebrew 安装 Boost),但遇到了同样的错误。
libbzip2 has been improperly configured for the current platform
所以我修复了它并添加了一些错误检查:
#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;
in.push(bzip2_decompressor());
in.push(file);
try
{
boost::iostreams::copy(in, cout);
}
catch (const bzip2_error& exception)
{
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;
}
}
> clang++ 18121908.cpp -lboost_iostreams -lboost_system -lboost_filesystem -o 18121908
> ./18121908
Can't find gcc-4.7.2.tar.bz2. Expect errors to follow!
bzip2 error
Error: -7
为什么是 -7
?因为 #define BZ_UNEXPECTED_EOF (-7)
。 Boost 调用此 bzip2::unexpected_eof
。您意外地到达了流的末尾!
> echo 'There should be some compiler stuff in here' > gcc-4.7.2.tar
> bzip2 gcc-4.7.2.tar
> ./18121908
There should be some compiler stuff in here
在尝试解压之前,您需要检查文件是否存在。
关于c++ - boost 库 iostream::copy 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18121908/
如何将 jQuery 代码转换为 React JS? 我有一个带有文本“复制”的按钮。当我单击它时,应将其文本更改为“已复制”并复制到剪贴板。复制后,几秒钟后我希望文本返回到“复制”。我相信以下功能将
在任何情况下我都想使用 NumPy 的 np.copy() 而不是 Python 的 copy.copy() 方法?据我所知,两者都创建浅拷贝,但 NumPy 仅限于数组。 NumPy 是否有任何性能
%python -m timeit -s "import copy" "x = (1, 2, 3)" "copy.deepcopy(x)" 100000 loops, best of 3: 10.1
我想制作一个列表的副本(字面意思是一个单独的克隆,与原始列表没有任何共享)。我使用了 copy.copy() 并创建了 2 个单独的列表,但为什么每个副本的元素似乎仍然共享? 这很难解释,请查看以下输
我不明白使用通配符时 COPY 命令的行为。 我在 C:\Source 中有一个文本文件叫 mpt*.asm我想把它复制到 C:\Dest .这是批处理脚本所需要的,我不能确定 mpt*.asm 的确
相关但不等同于:Golang: How to copy Context object without deriving 是否可以推导出 context.WithTimeout来自 context.Ba
您可以实现 Copy 特性来为类型提供复制语义而不是 move 语义。仅当其所有组成元素(产品类型的每个因素,或总和类型的每个变体的每个因素)也都是复制时,才能执行此操作。 这还允许您制作相当大的类型
我有一段代码,我需要确定编码值的类型,但我不知道它是字符串、无符号整数还是字符串的矢量。我想做以下几件事:。然而,来自弯曲板条箱的值不能实现复制,它在调用Decode_Bencode_Object之后
我需要复制一些对象,我读到 copy.copy 模块可以在 Python 上执行此操作。问题是,这些对象有一些属性是长数组。 那么这个方法效率高吗?由于性能在我所做的这项工作中很重要。 有更好的方法吗
我尝试高效地制作 lua 表的副本。我编写了以下运行良好的函数 copyTable()(见下文)。但我想我可以使用函数的“按值传递”机制获得更高效的东西。我做了一些测试来探索这个机制: functio
使用 pry 插件:pry-clipboard 当我输入“copy-history”来复制我历史的最后一行时,它实际上是在复制“copy-history”并粘贴“copy-history”。 我是不是
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 11 个月前关闭。 Improve this
我不了解Kotlin中通过访问器处理字段和复制方法之间的区别。就像这样: 访问者示例: class Person(val name: String, var age: Int
如何从节点复制一些属性。例如。我只想从节点“Extn”复制“Srno”,“RollNo”,“right”。
我有以下两个 XSL 转换,我希望将它们链接到一个 XSL 文件中。 第一次转换: 第二个转换(使用第一个转换的输出作为输入): 我的目标是从 WSDL
我是 Vertica DB 的新手,之前使用过 Mysql。我想在 vertica 表中插入唯一记录,但 vertica 在插入时不支持唯一约束。我通过 COPY 查询在表中插入记录。所以我无法在插入
std::copy 与执行策略参数之间是否存在正式关系?无论是在实践中还是在标准中。 例如,会不会只是这样, namespace std{ template It copy(std::
我用 root 运行了以下命令来备份同一主机上的文件夹:cp -r master 主备 size of master : 76GB size of master-backup : 71GB 知道为什么
我遇到过一段代码,乍一看似乎毫无意义。但我意识到这可能会产生一些我不知道的未知含义,因为 Python 不是我最熟悉的语言。 import copy node = copy.copy(node) 阅读
我正在设计一个基类,我希望它为 copy.copy 定义基本行为。此行为包括在控制台中打印警告,然后复制实例,就好像它没有 __copy__ 一样。属性。 当定义一个空白时Foo类并复制它的一个实例,
我是一名优秀的程序员,十分优秀!