c++ - 字符串文字 C++?

标签 c++ string

我需要在 C++ 中执行以下 C# 代码(如果可能)。我必须构造一个长字符串,里面有很多奇怪的引号和其他东西。

const String _literal = @"I can use "quotes" inside here";

最佳答案

这在 C++03(当前标准)中不可用。

这是 C++0x 草案标准的一部分,但目前还没有现成的。

现在,您只需明确引用它:

const std::string _literal = "I have to escape my quotes in \"C++03\"";

一旦 C++0x 成为现实,您就可以编写:

const std::string _literal = R"(but "C++0x" has raw string literals)";

当你需要 )" 在你的文字中:

const std::string _literal = R"DELIM(more "(raw string)" fun)DELIM";

关于c++ - 字符串文字 C++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2597322/

相关文章:

java - 如何将所有数组排列迭代返回为二维数组?

C题: why is my 20 length string limits itself with 6 chars?

string - bash 的浮点运算

c++ - glDisableVertexAttribArray 在一个 Visual Studio 解决方案中工作,但在另一个解决方案中不工作

c++ - QT:使用字段间规则进行表单验证

c++ - 函数返回如何返回特定计数

ios - 如何通过标题的第一个字母创建字典但忽略 "the"或 "a/an"等文章

c++ - 编译器没有发现歧义

c++ - 模板类的静态模板字段?

c - 谷歌 : Divide and return result in form of string