1 |
jgs |
82 |
#include <iostream> |
2 |
|
|
#include <sstream> |
3 |
|
|
namespace { |
4 |
|
|
char tmp = 'a'; |
5 |
|
|
}; |
6 |
|
|
class ErrStream |
7 |
|
|
{ |
8 |
|
|
public: |
9 |
|
|
template <typename Tmpl> |
10 |
|
|
ErrStream operator<<(Tmpl t) |
11 |
|
|
{ |
12 |
|
|
std::stringstream str; |
13 |
|
|
str << t; |
14 |
|
|
m_msg += str.str(); |
15 |
|
|
|
16 |
|
|
return *this; |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
const std::string &getMsg() const |
20 |
|
|
{ |
21 |
|
|
return m_msg; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
std::string m_msg; |
25 |
|
|
}; |
26 |
|
|
|
27 |
|
|
std::ostream &operator<<(std::ostream &oStream, const ErrStream &errStream) |
28 |
|
|
{ |
29 |
|
|
oStream << errStream.getMsg(); |
30 |
|
|
return oStream; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
int main(int argc, char *argv[]) |
34 |
|
|
{ |
35 |
|
|
int tmp = 0; |
36 |
|
|
{ |
37 |
|
|
char tmp = 'A'; |
38 |
|
|
std::stringstream tmpStr; |
39 |
|
|
tmpStr << tmp; |
40 |
|
|
std::cout << tmp << " " << (ErrStream() << "give out garbage" << tmp << "hi jimmy here is a float: " << 2.333).getMsg() << std::endl; |
41 |
|
|
std::cout << tmpStr.str() << std::endl; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
std::cout << tmp << std::endl; |
45 |
|
|
} |
46 |
|
|
|