简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!
优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀
人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.

本篇目的:在Android代码中:例如:“–display-id"s、”–dispsync"s等这种用法会让开发者疑惑,其实这是C++11字符串字面量后缀的用法,用作类型转换,下文来讲解它的用法。

C++11引入了字符串字面量后缀,可以用于在字符串字面量的末尾添加后缀以指定其类型。这样做的好处是增强了类型安全性,使得字符串字面量可以根据后缀的类型进行解析和处理。
以下是一些常用的字符串字面量后缀:
后缀"s":用于表示字符串字面量,其类型为const char[]。例如:"hello"s表示类型为const char[]的字符串。
后缀"u8":用于表示UTF-8字符串字面量,其类型为const char[]。例如:"你好"u8表示类型为const char[]的UTF-8字符串。
后缀"u":用于表示宽字符字符串字面量,其类型为const wchar_t[]。例如:L"hello"u表示类型为const wchar_t[]的宽字符字符串。
后缀"U":用于表示Unicode字符串字面量,其类型为const char32_t[]。例如:U"hello"表示类型为const char32_t[]的Unicode字符串。
后缀"L":用于表示宽字符串字面量,其类型为const wchar_t[]。例如:L"hello"表示类型为const wchar_t[]的宽字符串。
这些字符串字面量后缀提供了更灵活的字符串字面量表示方式,可以根据需要选择适合的类型和编码方式。
#include
#include
#include
using namespace std::literals::string_literals;
int main() {
//v1.0 char16_t*转char*
const char16_t *str1 = u"Test char16_t";
std::string str3 = converter.to_bytes(str1);
printf("xxx--------------->%s(), line = %d, str3 = %s\n",__FUNCTION__,__LINE__,str3.c_str());
return 0;
}
#include
#include
#include
using namespace std::literals::string_literals;
int main() {
std::string message = "Hellow"s;
std::cout << message << std::endl;
return 0;
}
const char[]#include
#include
#include
using namespace std::literals::string_literals;
int main() {
const char* str2 = u8"你好";
std::cout << str2 << std::endl;
return 0;
}
const wchar_t[]#include
#include
#include
using namespace std::literals::string_literals;
int main() {
const wchar_t* str3 = L"hello";
std::wcout << str3 << std::endl;
return 0;
}
#include
#include
int main() {
std::wstring wideString = L"Hello";
std::wcout << wideString << std::endl;
return 0;
}
#include
#include
int main() {
std::complex<double> complexNumber = 1.0 + 2.0i;
std::cout << complexNumber << std::endl;
return 0;
}
#include
#include
int main() {
std::complex<float> complexNumber = 1.0 + 2.0if;
std::cout << complexNumber << std::endl;
return 0;
}