O'Reilly logo

C++ All-in-One For Dummies, 3rd Edition by John Paul Mueller, Jeff Cogswell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2

Working with User-Defined Literals (UDLs)

In This Chapter

arrow Considering the needs and uses for UDLs

arrow Using the UDL features of the Standard Library

arrow Developing custom UDLs

Previous chapters have discussed literals as a kind of constant. For example, in the expression X = 5, the number 5 is a literal constant. The constant X stands in for the value 5 in application code. Using a literal makes it possible to create code that states the use of a value clearly, rather than having code that is filled with mystery values that no one can figure out. In addition, using literals makes it possible to change constant values in one place, rather than in each place they’re needed in an application.

Up to this point, you have used every other kind of literal constant in the various examples except for User-Defined Literals (UDLs). Unlike other kinds of literal constants, a UDL isn’t defined as part of the C++ compiler — you create UDLs as needed to make your code more readable and easier to manage. In some cases, UDLs come with the libraries you use in C++, such as the Standard Library. This chapter does discuss UDLs that come as part of the Standard Library, but it also looks at how you’d ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required