Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the operator "" in C++?

I fell on this page where the author talks about the standardisation of the operator "":

The decision of the C++ standards committee to standardise operator "" was [...]

What is he/she talking about? I can't find any information about this, and I don't understand what it could imply (overload for constant strings? Or something more conceptual, that doesn't affect the final use of the language?)

like image 582
yolenoyer Avatar asked Mar 16 '17 12:03

yolenoyer


People also ask

Which operator is == in C?

The '==' operator checks whether the two given operands are equal or not. If so, it returns true. Otherwise it returns false.


1 Answers

Those are user-defined literals. They allow you to create stuff like std::string, std::chrono::durations or any user defined type (you can make your own literals) in place:

auto str = "Hello"s; // str is std::string("Hello") auto sec = 5s;       // sec is 5 std::chrono::seconds 

A list of the literal-operators provided by the standard library and their documentation can be found at the bottom of the documentation page I linked.

like image 192
Baum mit Augen Avatar answered Oct 11 '22 03:10

Baum mit Augen