Site icon Learn C++

What Is std::quoted Quoted String In Modern C++?

What Is stdquoted Quoted String In Modern C++

Sometimes we want to preserve the string format especially when we use string in a string with /”. In C++14 and above, there is a std::quoted template that allows handling strings safely where they may contain spaces and special characters and it keeps their formatting intact. In this post, we explain std::quoted quoted strings in modern C++.

What Is Quoted String In Modern C++?

The std::quoted template is included in <iomanip> header, and it is used to handle strings (i.e. “Let’s learn from \”LearnCPlusPlus.org!\” “) safely where they may contain spaces and special characters and it keeps their formatting intact. 

Here is the syntax,

[crayon-6646f6380c4cd393929105/]

Here are C++14 templates defined in <iomanip> where the string is used as input,

[crayon-6646f6380c4d5810720969/]

or

[crayon-6646f6380c4d7515551206/]

Here is a C++14 template defined in <iomanip> where the string is used as output,

[crayon-6646f6380c4d9868683552/]

Note that this feature is is using std::basic_string and it improved in C++17 by the  std::basic_string_view support.

What Is std::quoted quoted string in modern C++?

Here is an example that uses input string and outputs into a stringstream:

[crayon-6646f6380c4db621473496/]

Here is an example that uses stringstream as an input and outputs into a string.

[crayon-6646f6380c4dd941875717/]

Is there a full example about std::quoted quoted string in modern C++?

Here is a full example about std::quoted in modern C++.

[crayon-6646f6380c4e0221191435/]

For more information about this feature, please see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3654.html

C++ Builder is the easiest and fastest C and C++ IDE for building powerful, good-looking applications. 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

Exit mobile version