3 ms·
Right. Also, the C version would be cleaner using the printf family of functions. Idiomatic C would use snprintf and accept a buffer. If you insist on returning
by millstone 12y ago
Right. Also, the C version would be cleaner using the printf family of functions. Idiomatic C would use snprintf and accept a buffer. If you insist on returning a heap-allocated object, you could use asprintf, which is not universal but is common. Either way it's a one-liner.
- nly 12y agoYeah, but as soon as you use snprintf you're throwing performance to the wind.The idiomatic C++ solution should beat it hands down. (gulp)
- vardump 12y agoHave you benchmarked that? Last I tried some not-so-rigorous microbenchmarks, *printf beat C++ << streams by a factor of 3 on msvc 11 (VS2012).