[lug] [OT] C++ trick?

Tkil tkil at scrye.com
Fri Jan 24 15:31:23 MST 2003


>>>>> "Scott" == Scott Herod <herod at dimensional.com> writes:

Scott> I want to create a macro to replace "itoa( i, buf, size )"
Scott> basically with a function like:

Why not use just such a function?

| template <class T>
| static inline
| string my_whatever_to_string( const T & x )
| {
|     std::ostringstream os;
|     os << x << std::ends;
|     return os.str();
| }

(You can put this in header files, since "static" forces file scope.)

The interface of 'itoa' (with the buffer etc) is a mess, but you could
fake it in similar ways.

t.



More information about the LUG mailing list