参见英文答案 > Representing big numbers in source code for readability? 5个
> Making large constants in C source more readable? 8个
想象一下,我有代码:
vector<int> temp = vector<int>(1 000 000 000);
上面不会编译,因为编译器会抱怨空格.是否可以指示C在编译时省略这些空格,或以其他方式使数字更容易阅读?
解决方法:
尝试数字分隔符:
int i = 1'000'000'000;
此功能在since C++14中引入.它使用单引号(‘)作为数字分隔符.
另见:
> Why was the space character not chosen for C++14 digit separators?
> Generalizing Overloading for C++2000(四月由C的父亲自己开玩笑)