如何在 C 或 C++ 代码中分隔数字常量(即 10,000)

How to separate digits in numeric constants (i.e. 10,000) in C or C++ code

Java 允许数字常量中的数字按如下方式分隔:

int a = 1_000_000;

C 或 C++ 是否有类似的结构?

你可以用 C++ 14 编写

int a = 1'000'000;

在 C 中没有这样的功能。

唯一的方法是在 C++14 中使用单引号,就像这样。不幸的是,唯一的问题是语法高亮显示经常会与下面的符号混淆,您也可以在我的示例中看到这一点:

int i = 1'000'000;


Working Example
根据 http://en.cppreference.com/w/cpp/language/user_literal:

In the integer and floating-point digit sequences, optional separators ' are allowed between any two digits and are ignored (since C++14)