很多时候我在互联网上找到有用的代码示例。大约有一半时间他们没有指定要包含什么文件,甚至没有指定包含在命令行中使用-l的库。你通常如何发现?C++要包含哪些文件和库?
编辑提示:以下问题已解决。这篇文章的其余部分可以跳过。
现在,我得到吨的错误,而试图编译:
53: string Gunzip::gunzip(string& compressed)
54: {
55: namespace io = boost::iostreams;
56:
57: io::filtering_istream gunzip;
58: gunzip.push(io::gzip_decompressor());
59: std::istringstream in_stream = std::istringstream(compressed);
60: gunzip.push(in_stream);
61:
62: stringstream strstream;
63: io::copy(gunzip, strstream);
64: return strstream.str();
65: }
在互联网上一整天后我想:
option: 3 -L/usr/include/boost
and:
8: #include <string>
9: #include <iostream>
10: #include <sstream>
15: #include <boost/iostreams/copy.hpp>
16: #include <boost/iostreams/device/array.hpp>
17: #include <boost/iostreams/device/back_inserter.hpp>
18: #include <boost/iostreams/filter/gzip.hpp>
19: #include <boost/iostreams/filter/test.hpp>
20: #include <boost/iostreams/filtering_stream.hpp>
我的错误是:
from /usr/include/c++/4.5/string:45,
from Gunzip.cpp:8:
/usr/include/c++/4.5/bits/ios_base.h: In copy constructor ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’:
In file included from /usr/include/c++/4.5/bits/localefwd.h:43:0,
/usr/include/c++/4.5/bits/ios_base.h:785:5: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
/usr/include/c++/4.5/iosfwd:77:11: error: within this context
/usr/include/c++/4.5/iosfwd: In copy constructor ‘std::basic_istringstream<char>::basic_istringstream(const std::basic_istringstream<char>&)’:
/usr/include/c++/4.5/iosfwd:97:11: note: synthesized method ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’ first required here
/usr/include/c++/4.5/streambuf: In copy constructor ‘std::basic_stringbuf<char>::basic_stringbuf(const std::basic_stringbuf<char>&)’:
/usr/include/c++/4.5/streambuf:773:7: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>::__streambuf_type&) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_streambuf<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]’ is private
/usr/include/c++/4.5/iosfwd:93:11: error: within this context
/usr/include/c++/4.5/iosfwd: In copy constructor ‘std::basic_istringstream<char>::basic_istringstream(const std::basic_istringstream<char>&)’:
/usr/include/c++/4.5/iosfwd:97:11: note: synthesized method ‘std::basic_stringbuf<char>::basic_stringbuf(const std::basic_stringbuf<char>&)’ first required here
Gunzip.cpp: In member function ‘std::string Gunzip::gunzip(std::string&)’:
Gunzip.cpp:59:65: note: synthesized method ‘std::basic_istringstream<char>::basic_istringstream(const std::basic_istringstream<char>&)’ first required here
make[2]: Leaving directory `/home/albert/NetBeansProjects/Arb3'
make[1]: Leaving directory `/home/albert/NetBeansProjects/Arb3'
make[2]: *** [build/Debug/GNU-Linux-x86/Gunzip.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 9s)
我可以删除前3个包含获取其他错误我不明白。我不知道哪些错误更好。
- 此错误是否包含?我应该怎么知道?我在指责包括,因为迄今为止所有的错误都是由于包括。我不知道basic_ios是什么。
- 你如何找出包含什么和使用哪些库?
请发布完整的错误。您发布的部分忽略了最相关的信息:哪部分代码导致了错误。 –
添加完整的错误。我还在代码中插入了一行。 –