C++相談室 part8
■ このスレッドは過去ログ倉庫に格納されています
0758デフォルトの名無しさん
NGNGこれでどう?
#include <iostream>
#include <sstream>
using namespace std;
class ErrorMessage {
ostringstream os;
public:
ErrorMessage( const char *file, int line ) {
os << file << "(" << line << "): ";
}
template<class T>
ErrorMessage& operator+( T x ) {
os << x;
return *this;
}
operator const string () const {
return os.str();
}
};
void foo( const string& s )
{
cout << s << endl;
}
int main()
{
int a = 10;
char b[] = "hogehoge";
foo( ErrorMessage(__FILE__, __LINE__) + "HOGE(" + a + ") " + b);
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています