很多時候我在互聯網上找到有用的代碼示例。大約有一半時間他們沒有指定要包含什麼文件,甚至沒有指定包含在命令行中使用-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是什麼。
- 你如何找出包含什麼和使用哪些庫?
請發佈完整的錯誤。您發佈的部分忽略了最相關的信息:哪部分代碼導致了錯誤。 –
添加完整的錯誤。我還在代碼中插入了一行。 –