我如何将文字转义符转换为“真实的”转义符,以便它们被“正确地”打印?

问题描述 投票:0回答:1

以下C ++代码应该很容易理解。在前两个“ cout”的注释中,有实际的打印内容。在第三个“ cout”注释中,有我要打印的内容。“ restore_escapes”函数应该是什么样?还没有准备好使用的东西吗?

std::string a("abc\"\tdef\n");
std::string b(R"(abc\"\tdef\n)");

std::cout << a; //abc"    def
std::cout << b; //abc\"\tdef\n
std::cout << restore_escapes(b);  //abc"    def
c++ string-literals
1个回答
1
投票

请参见glib g_strcompress function,在此处转载:

g_strcompress
© www.soinside.com 2019 - 2024. All rights reserved.