In the history of modern C++, the C++14 standard brings us some very useful features. C++14 comes with the digit seperators feature. In C++14 and above, we can use the digit separator to separate integer numbers. In this post, we explain, how to use digit separators in examples,
How can I use use digit separators in modern C++?
In C++14, there is a new Digit Separators feature. The digit separator is a single-quote character ‘ that can be used within a numeric literal for aesthetic readability. When you use digit separators, it does not affect the numeric value, but it is very useful when you are using bigger or longer digital numbers. It can be used with int
, long int
, long long int
, float
, double
, auto
, etc.
Here is a simple example to digit separators.
1 2 3 |
long long int LL = 123'456'789; |
Is there a full example about to use digit separators in modern C++
Here is a full example about to use digit separators in modern C++.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <iostream> #include <iomanip> int main() { int x = 1'024; unsigned int m = 128'000'000; long double pi = 3.141'592'653'589; long long int LL = 123'456'789; std::cout << x << std::endl; std::cout << m << std::endl; std::cout << std::fixed << std::setprecision(12) << pi << std::endl; std::cout << LL << std::endl; system("pause"); return 0; } |
and the output will be as follows:
1 2 3 4 5 6 |
1024 128000000 3.141592653589 123456789 |
Note that, C++ Builder IDE also supports digit seperators.
For more details, please see this digit separators https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3499.html
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise version.
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition