kap*_*dit -6 c c++ floating-point pointers
我有这样的问题:
char *ptr;
float f1 = 12.34;
Run Code Online (Sandbox Code Playgroud)
现在使用这个char*ptr,我想将这个float值转换为string,可以使用这个指针"ptr"在printf中显示.
表示:12.34 ==>"12.34"
我不需要使用任何其他指针或临时变量.我不能用snprintf.
OP标记了C++,所以这里..
std::stringstream ss;
ss << f1;
std::string s = ss.str();
ptr = s.c_str();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
189 次 |
| 最近记录: |