C++: what is the optimal way to convert a double to a string?

后端 未结 12 1768
温柔的废话
温柔的废话 2020-12-16 17:09

What is the most optimal way to achieve the same as this?

void foo(double floatValue, char* stringResult)
{
    sprintf(stringResult, \"%f\", floatV         


        
12条回答
  •  北海茫月
    2020-12-16 17:25

    This is very useful thread. I use sprintf_s for it but I started to doubt if it is really faster than other ways. I came across following document on Boost website which shows performance comparison between Printf/scanf, StringStream and Boost.

    Double to String is most common conversion we do in our code, so i'll stick with what i've been using. But, using Boost in other scenarios could be your deciding factor.

    http://www.boost.org/doc/libs/1_58_0/doc/html/boost_lexical_cast/performance.html

提交回复
热议问题