C++11 新添加的变量定义后缀支持

Standard user-defined literals[edit]
C++11 defined the syntax for user-defined literal suffixes, but the standard library did not use any of them. C++14 adds the following standard literals:[16]
“s”, for creating the various std::basic_string types.
“h”, “min”, “s”, “ms”, “us”, “ns”, for creating the corresponding std::chrono::duration time intervals.
“if”, “i”, “il”, for creating the corresponding std::complex, std::complex and std::complex imaginary numbers.

auto str = "hello world"s; // auto deduces string
auto dur = 60s;            // auto deduces chrono::seconds
auto z   = 1i;             // auto deduces complex<double>

The two “s” literals do not interact, as the string one only operates on string literals, and the one for seconds operates only on numbers.[18]

猜你喜欢

转载自blog.csdn.net/shujianlove0/article/details/84564561