Many times I find useful code examples on the Internet. About half of the time they don't specify what files to include or even what libs to include on the command line with -l. How do you usually find that out?
edit note: The problem below has been solved. The remainder of this post can be skipped.
Right now, I'm getting tons of errors while trying to compile:
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: }
After a day on the Internet I'm trying:
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>
The error I have is:
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)
I can remove the first 3 includes to obtain other errors I don't understand. I don't know which errors are better.
The short answer is 'it depends'. For classes / functions which are part of the C++ standard library the man pages which come with your compiler will list which header(s) and libraries are required; or alternately you can use online resources such as cplusplus.com, MSDN or GNU libstdc++ doxygen docs.
For things like Boost you have to look at their documentation; however the obvious question is 'how do I know if a class is from boost' - to which the answer is pretty much 'Google it' - over time you'll get used to what is and isn't in Boost.