当我尝试在Qt 4.8中使用llvm-g++-4.2 (GCC) 4.2.1编译下面的代码时,会出现以下错误:
../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
这个错误是什么意思?我该怎么修复它呢?
源代码:
#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();
}
#include <ostream>
。 - user93353-mmacosx-version-min=10.7
添加为编译标志。 - Chad Campbelliostream
不需要包含#include <ostream>
。 - Sebastian Machos << test;
这一行,并且抱怨std::operator<<
函数。 - aschepler