Easiest way to convert int to string in C++

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

    C++11 introduced std::to_string() for numeric types:

    int n = 123; // Input, signed/unsigned short/int/long/long long/float/double
    std::string str = std::to_string(n); // Output, std::string
    

提交回复
热议问题