Easiest way to convert int to string in C++

后端 未结 28 2281
甜味超标
甜味超标 2020-11-21 06:42

What is the easiest way to convert from int to equivalent string in C++. I am aware of two methods. Is there any easier way?

(1)



        
28条回答
  •  抹茶落季
    2020-11-21 07:21

    I use:

    int myint = 0;
    long double myLD = 0.0;
    
    string myint_str = static_cast(&(ostringstream() << myint))->str();
    string myLD_str = static_cast(&(ostringstream() << myLD))->str();
    

    It works on my Windows and Linux g++ compilers.

提交回复
热议问题