C++ 整数转换为字符串

时间:2023-01-07 08:53:39
 使用stringstream类:(强烈推荐)

           #include <iostream>

           #include <sstream>   

          using namespace std;
    
            int main()
          {
             int i = 10;   
    
              stringstream   strstr;   
             strstr << i;   
    
             string str(strstr.str());   
    
             cout << "str = " << str << std::endl;   
            }