K
Kai-Uwe Bux
Hi folks,
I have trouble writing a class, derving from stringstream, that collects
item and once it's done will write them to std::cout in one go. It works
fine except when I use it as a temporary. Here is a tiny test programm:
#include <iostream>
#include <sstream>
class Gatherer : public std::stringstream {
public:
~Gatherer ( void ) {
std::cout << this->str() << std::endl;
}
};
int main ( void ) {
{
Gatherer() << "hello world!";
}
{
Gatherer gather;
gather << "hello world!";
}
{
Gatherer() << std::dec << "hello world!";
}
}
On my machine, it prints:
0x8049e48
hello world!
hello world!
So, clearly the first line is an address. I have no explanation for this. I
am especially puzzled by the third line. Inserting a std::dec should not
have this effect, or should it?
Best regards
Kai-Uwe
I have trouble writing a class, derving from stringstream, that collects
item and once it's done will write them to std::cout in one go. It works
fine except when I use it as a temporary. Here is a tiny test programm:
#include <iostream>
#include <sstream>
class Gatherer : public std::stringstream {
public:
~Gatherer ( void ) {
std::cout << this->str() << std::endl;
}
};
int main ( void ) {
{
Gatherer() << "hello world!";
}
{
Gatherer gather;
gather << "hello world!";
}
{
Gatherer() << std::dec << "hello world!";
}
}
On my machine, it prints:
0x8049e48
hello world!
hello world!
So, clearly the first line is an address. I have no explanation for this. I
am especially puzzled by the third line. Inserting a std::dec should not
have this effect, or should it?
Best regards
Kai-Uwe