Easiest way to convert int to string in C++

后端 未结 28 1816
甜味超标
甜味超标 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:20

    namespace std
    {
        inline string to_string(int _Val)
        {   // Convert long long to string
            char _Buf[2 * _MAX_INT_DIG];
            snprintf(_Buf, "%d", _Val);
            return (string(_Buf));
        }
    }
    

    You can now use to_string(5).

提交回复
热议问题