#include <string>  
#include <sstream>    //使用stringstream需要引入这个头文件  

//模板函数:将string类型变量转换为常用的数值类型(此方法具有普遍适用性)  
    template <class Type>  
    Type CurveDataModel::stringToNum(const std::string& str){  
            std::istringstream iss(str);  
            Type num;  
            iss >> num;  
            return num;      
    }  

使用方法(尖括号中可以是任何类型的数字):feature_id = stringToNum<unsigned int>());

数字转string

#define varName(x) #x  

使用方法:

std::string temp(varName(feature_id));

相关文章:

  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2021-08-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2021-09-14
相关资源
相似解决方案