C++11 user-defined literals
#define_crt_secure_no_warnings#include<iostream>#include<string>#include<vector>#include<map>//user-defined literals, or "custom suffixes", are more intuitive, and the main purpose is to simplify the reading and writing of code. Long Double operator""_MM (Long Doublex) {returnX/ +; }Long Double operator""_m (Long Doublex) {returnx;}Long Double operator""_KM (Long Doublex) {returnX * +; }/*according to the C + + 11 standard, only the following parameter list is valid char const *unsigned LONG longlong Doublechar const *, size_twchar_t const *, size_tchar16 _t Const *, size_tchar32_t const *, size_t the last four are quite useful for strings, because the second argument is automatically inferred as the length of the string*/size_toperator""_len (Char Const*str, size_t size) { returnsize;}//for the parameter Char const *, it should be called the original literal raw literal operator.Char Const*operator""_r (Char Const*str) { returnstr;}voidmytest () {std::cout<<1.0_mm << Std::endl;//0.001Std::cout <<1.0_m << Std::endl;//1Std::cout <<1.0_km << Std::endl;// +Std::cout<<"XYZ"_len << Std::endl;//result is 3Std::cout<< 250_r << Std::endl;//The result is return;}intMain () {mytest (); System ("Pause"); return 0;}
C++11 user-defined literals