C++ 无法打印字符串流,但打印指针
这是我的代码:C++ 无法打印字符串流,但打印指针,c++,c++03,C++,C++03,这是我的代码: #include <iostream> #include <sstream> #include <string> using namespace std; class TestLog: public std::stringstream { public: ~TestLog() { cout << (st
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
class TestLog: public std::stringstream
{
public:
~TestLog()
{
cout << (str()) << endl; // Why does this print an address ?
}
};
int main()
{
TestLog() << "Hello World!"; //test 1 print an address
stringstream ss;
ss << "Hello World!";
cout << (ss.str()) << endl; //test 2 print a string
return 0;
}
#包括
#包括
#包括
使用名称空间std;
类TestLog:public std::stringstream
{
公众:
~TestLog()
{
coutssss你在使用哪个编译器?也会打印正确的结果。g++(GCC)4.8.5 20150623(Red Hat 4.8.5-11)。当编译为C++03时会出现这种行为。我为你添加了标记。你在使用哪个编译器?也会打印正确的结果。g++(GCC)4.8.5 20150623(Red Hat 4.8.5-11)。当编译为C++03时会出现这种行为。我为您添加了标记。
template <class Traits>
std::basic_ostream<char, Traits> &std::operator << (
std::basic_ostream<char, Traits> &os, char const *s
);
TestLog tl;
tl << "Hello World!";
std::basic_ostream &std::basic_ostream::operator << (void const *value);
template <class CharT, class Traits, class T>
std::basic_ostream<CharT, Traits> &operator << (
basic_ostream<CharT, Traits> &&os, T const &value
);