Is there a way to write a large number in C++ source code with spaces to make it more readable?(有没有办法在 C++ 源代码中用空格编写大量数字以使其更具可读性?)
问题描述
假设我有代码:
vector<int> temp = vector<int>(1 000 000 000);
以上不会编译,因为编译器会抱怨空格.是否可以指示 C++ 在编译时省略这些空格,或者以其他方式使数字更易于阅读?
The above will not compile as the compiler will complain about the spaces. Is it possible to indicate to C++ to ommit those spaces when compiling, or otherwise make the number easier to read?
推荐答案
试试数字分隔符:
int i = 1'000'000'000;
此功能是 自 C++14 引入的.它使用单引号 ('
) 作为数字分隔符.
This feature is introduced since C++14. It uses single quote ('
) as digit separator.
另见:
- 为什么没有为 C++14 数字分隔符选择空格字符?
- 泛化 C++2000 的重载(C++ 之父 4 月的笑话)
- Why was the space character not chosen for C++14 digit separators?
- Generalizing Overloading for C++2000 (April's joke by the father of C++ himself)
这篇关于有没有办法在 C++ 源代码中用空格编写大量数字以使其更具可读性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有没有办法在 C++ 源代码中用空格编写大量数字以使其更具可读性?


基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01