- 用户自定义自面类型。第一次看到支持这个,很是吃惊!
- 如果字面量为整形数,那么字面量操作符只可接受unsigned long long。
- 如果字面为浮点数时,则字面可以接受的是long double;
- 如果字面量为字符串,则字面量操作符函数只可接受const char*,和size_t为参数,此size_t由编译器自动传入值。
- 如果字面量为字符,则字面量操作符函数只可一个char为参数。
#include <iostream> #include <cctype> using namespace std; void operator "" _C(char t) { cout <<(char) toupper(t)<<endl; } void operator "" _S(const char* t,size_t n) { //此处n为隐式直接传入,不需要在显示指定,其根据传入字符串长度,由编译器传入 int i =0; while(i < n) { cout << (char)toupper(*(t+i++)); } cout << endl; } void operator "" _I(unsigned long long i) { cout << "this is a long long !"<<endl; } void operator "" _F(long double t) { cout << "in double long F"<<endl; } int main() { "ddd mfdfdafjda,fdfd"_S;//DDD
c++/c学习笔记--补遗
最新推荐文章于 2021-03-12 21:15:05 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)