使用sprintf格式化负整数/双精度(Format negative integer/double using sprintf)

编程入门 行业动态 更新时间:2024-10-22 18:48:35
使用sprintf格式化负整数/双精度(Format negative integer/double using sprintf)

是否有可能只使用sprintf(c ++)格式化负整数/双精度,使得符号和值之间有空格?

from this: -1234 to this: - 1234

编辑:它将进入一个char数组。

is it possible using only sprintf (c++) to format a negative integer/double in a way that there is a space between the sign and the value?

from this: -1234 to this: - 1234

Edit: It will go in a char array.

最满意答案

我意识到这不是问题,但因为它被标记为C ++:

std::ostringstream out; out << std::internal << std::setw(6) << -1234; std::string result = out.str();

I realize that this isn't the question but since this is tagged as C++:

std::ostringstream out; out << std::internal << std::setw(6) << -1234; std::string result = out.str();

更多推荐

本文发布于:2023-07-24 00:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239269.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   精度   sprintf   Format   double

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!