Re: Конкатенация строк и чисел в С++ одним выражением
От: astral_marine  
Дата: 23.03.06 10:21
Оценка:
#define _S(msg)   (((std::basic_ostringstream<TCHAR>&)(((std::basic_ostringstream<TCHAR>&)std::basic_ostringstream<TCHAR>()) << msg)).str())

#define _SA(msg)  (((std::basic_ostringstream<char>&)(((std::basic_ostringstream<char>&)std::basic_ostringstream<char>()) << msg)).str())
#define _SW(msg)  (((std::basic_ostringstream<wchar_t>&)(((std::basic_ostringstream<wchar_t>&)std::basic_ostringstream<wchar_t>()) << msg)).str())

float a = 1.1;
SetError(_S("Ошибка в файле: " << FILE_NAME << 12 << 12.16 << a));


Код работает в Visual C++ 6.0, 2003
В GCC можно делать так:
template <class charT>
class str_helper : public std::basic_ostringstream<charT> 
{
public:
    std::basic_ostringstream<charT> & getRef()
    {
        return *static_cast<std::basic_ostringstream<charT> *>(this);
    }
};

#define _S(msg) (((std::basic_ostringstream<TCHAR>*)&( str_helper<TCHAR>().getRef() << msg))->str())
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.