为什么以下不再是有效的 C++11 代码(编译为 C++98):
#include <sstream>
#include <iostream>
int main()
{
std::ostringstream os;
os << "Hello World!";
std::cout << os << std::endl;
return 0;
}
这里的参考是(截断)我用clang得到的:
$ clang++ -stdlib=libc++ -std=c++11 t.cxx
t.cxx:8:13: error: invalid operands to binary expression ('ostream' (aka 'basic_ostream<char>') and 'std::ostringstream' (aka 'basic_ostringstream<char>'))
std::cout << os << std::endl;
~~~~~~~~~ ^ ~~
/usr/include/c++/v1/ostream:190:20: note: candidate function not viable: no known conversion from 'std::ostringstream' (aka 'basic_ostringstream<char>') to
'const void *' for 1st argument; take the address of the argument with &
basic_ostream& operator<<(const void* __p);