重新源$ C ​​$ C以增强可读性presenting大的数字?

编程入门 行业动态 更新时间:2024-10-28 04:21:11
本文介绍了重新源$ C ​​$ C以增强可读性presenting大的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有书面的C ++或C?

Is there a more human-readable way for representing big numbers in the source code of an application written in C++ or C?

让我们比如拿号 2,345,879,444,641 ,C或C ++如果我们想要一个程序来恢复这个数字,我们会做返回2345879444641 。

let's for example take the number 2,345,879,444,641 , in C or C++ if we wanted a program to return this number we would do return 2345879444641.

但是,这是不是真的读。

But this is not really readable.

在PAWN(一种脚本语言)比如我可以做收益2_345_879_444_641 甚至收益2_34_58_79_44_46_41 键,这些都将返回数 2,345,879,444,641 。

In PAWN (a scripting language) for example I can do return 2_345_879_444_641 or even return 2_34_58_79_44_46_41 and these both would return the number 2,345,879,444,641.

这是对人眼更具有可读性。

This is much more readable for the human-eye.

是否有一个C或C ++相当于呢?

Is there a C or C++ equivalent for this?

推荐答案

下面是一个宏,将做到这一点,在两个MSVC和GCC测试。在升压不依赖...

Here's a macro that would do it, tested on both MSVC and GCC. No reliance on Boost...

#define NUM(...) NUM_(__VA_ARGS__, , , , , , , , , , ) #define NUM_(...) NUM_MSVCHACK((__VA_ARGS__)) #define NUM_MSVCHACK(numlist_) NUM__ numlist_ #define NUM__(a1_, a2_, a3_, a4_, a5_, a6_, a7_, a8_, ...) a1_##a2_##a3_##a4_##a5_##a6_##a7_##a8_

使用它像:

int y = NUM(1,2,3,4,5,6,7,8); int x = NUM(100,460,694);

产地:

int y = 12345678; int x = 100460694;

更多推荐

重新源$ C ​​$ C以增强可读性presenting大的数字?

本文发布于:2023-11-06 01:56:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:新源   可读性   数字   presenting

发布评论

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

>www.elefans.com

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