Files
python/C++专题课程/字符串操作/convertNumToStr.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
470 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<bits/stdc++.h>
using namespace std;
/**
* 功能:将指定的数字转为字符串
* 作者:黄海
* 时间2019-10-31
* @param a
* @return
*/
string convertNumToStr(double a) {
string res;
//定义流ss
stringstream ss;
ss << a;
//将数字a转化成流ss
ss >> res;
//将流ss转化成字符串
return res;
}
int main() {
double a = 123.32;
string a_str=convertNumToStr(a);
cout << a_str<< endl;
return 0;
}