相关疑难解决方法(0)

用户定义的文字为C++添加了哪些新功能?

C++ 11引入了用户定义的文字,这将允许基于现有文本(采用新的文本语法的int,hex,string,float),使得任何类型的将能够具有字介绍.

例子:

// imaginary numbers
std::complex<long double> operator "" _i(long double d) // cooked form
{ 
    return std::complex<long double>(0, d); 
}
auto val = 3.14_i; // val = complex<long double>(0, 3.14)

// binary values
int operator "" _B(const char*); // raw form
int answer = 101010_B; // answer = 42

// std::string
std::string operator "" _s(const char* str, size_t /*length*/) 
{ 
    return std::string(str); 
}

auto hi = "hello"_s …
Run Code Online (Sandbox Code Playgroud)

c++ user-defined-literals c++11

138
推荐指数
8
解决办法
3万
查看次数

标签 统计

c++ ×1

c++11 ×1

user-defined-literals ×1