什么是运算符“"?在C ++中? [英] What is the operator "" in C++?
问题描述
我跌倒了此页面,作者在其中谈论了运算符" :
I fell on this page where the author talks about the standardisation of the operator "":
C ++标准委员会关于标准化
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?)
推荐答案
这些是用户-定义的文字.它们使您可以就地创建std::string
,std::chrono::durations
之类的东西或任何用户定义的类型(您可以创建自己的文字):
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.
这篇关于什么是运算符“"?在C ++中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!