When I try to compile the code below (in a Qt 4.8 using llvm-g++-4.2 (GCC) 4.2.1), I get the following error:
../GLWidget.cpp:24: instantiated from here
../GLWidget.cpp:24: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
What does this error mean, and what should I do to fix it?
Source code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void testOStream(){
filebuf fb;
fb.open ("test.txt",ios::out);
std::ostream os(&fb);
std::string test("test");
os << test; // This line has the problem
fb.close();
}
If you are using a C++ version prior C++11, you may want to add #include <ostream>
to your program.
Only with C++11 and later <iostream>
is required to #include <ostream>
.
<iostream>
synopsisC++2003:
namespace std { extern istream cin; extern ostream cout; extern ostream cerr; extern ostream clog; extern wistream wcin; extern wostream wcout; extern wostream wcerr; extern wostream wclog;
}
C++2011:
#include <ios> #include <streambuf> #include <istream> #include <ostream> namespace std { extern istream cin; extern ostream cout; extern ostream cerr; extern ostream clog; extern wistream wcin; extern wostream wcout; extern wostream wcerr; extern wostream wclog; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With