C++C++11C++14C++17C++20Learn C++

What Are The Standard User-Defined Literals In C++14?

What Are The Standard User Defined Literals In C++14

C++11 introduced new forms of literals using modified syntax and semantics to provide User-Defined Literals (UDL) also known as Extensible Literals. While there was the ability to use them the standard library did not use any of them. In C++14, the commission added some standard literals. In this post, we explain user-defined literals operators and we explain some of these standard literals added in C++14.

What are the user defined literal operators in C++?

C++11 introduced new forms of literals using modified syntax and semantics in order to provide User-Defined Literals (UDL) also known as Extensible Literals. Using user-defined literals, user-defined classes can provide new literal syntax and they can be used with the operator "" to combine values with conversion operators. Here below, we explain how to use user-defined literals in C++.

What are the standard user-defined literals in C++14?

In C++14, we have some standard user-defined literal operators that comes with standard library. These are literals for basic strings, for chrono types, and for complex number types.

We can access to these operators by:

  • using namespace std::literals;
  • using namespace std::string_literals;
  • using namespace std::literals::string_literals;

C++14 adds the following standard literals below,

For the string types there is an operator”” s() for basic string,

  • s : std::basic_string types for creating the various string types std::string, std::wstring, etc.

here how we can use it with auto,

Suffixes for std::chrono::duration values,

  • h : hour type for the std::chrono::duration time intervals
  • m : minute type for the std::chrono::duration time intervals
  • s : second type for the std::chrono::duration time intervals
  • ms : millisecond type for the std::chrono::duration time intervals
  • ns : nanosecond type for the std::chrono::duration time intervals
  • us : u.second type for the std::chrono::duration time intervals

here how we can use them with auto,

Suffixes for complex number literals,

  • if : imaginary number for the std::complex<float> types
  • i : imaginary number for the std::complex<double> types
  • il : imaginary number for the std::complex<long double> types

here how we can use them with auto,

there are more definitions.

Is there a full example of how to use standard user-defined literals in C++14?

Here is a full example about standard user-defined literals in C++.

For more information about the standard user-defined literals, please see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3402.pdf

What Are The Standard User Defined Literals In C++14 C++ Builder logo

C++ Builder is the easiest and fastest C and C++ compiler and 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 versions of C++ Builder and there is a trial version you can download from here.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
Artificial Intelligence TechC++C++11C++14C++17Language FeatureLearn C++

Learn How To Read The WAV Waveform Audio File Format In C++

C++C++11Learn C++

What Is Assignment Operator Overloading?

C++C++11Introduction to C++Learn C++Syntax

Full List Of Features In C++ 11

C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

How To Use Basic Methods Of Strings In C++?