c# - 在 C++ 中创建原始文本字符串,类似于 C#'s "@string"

标签 c# c++ string string-literals

我要从 C# 转到 C++。我有一个带有很多反斜杠的字符串,我想将该字符串作为原始文本读取。 C++ 有类似 C# 的“at string”吗?例如:

string s = @"\\Some\Path";

在我使用的 C++ 文件中:

#include <string>

最佳答案

您可以使用原始字符串文字:

std::string s = R"(\Some\Path)";

此功能在 C++11 中可用。

请注意,对于文件系统路径,您可以使用正斜杠:

std::string s = "/Some/Path";

关于c# - 在 C++ 中创建原始文本字符串,类似于 C#'s "@string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18151117/

相关文章:

c# - Enumerable.OrderBy如何使用keySelector

c# - ninject NinjectWebCommon 黑魔法

c++ - 为什么不能使用 '( )' 为类的非静态数据成员赋予默认值?

python - 通过使用 Python 分成多行来限制字符串宽度

c++ - C4503 警告?我该如何解决/摆脱它们?

c - 字符串文字是否在 C 的编译时自动转换为 char*?

c# - 如何使用 ConfigurationElementCollection 实现 ConfigurationSection

c# - 使用 MVVM 与组合框绑定(bind) ObservableCollection 或列表数据?

c++ - 将 const char[] 初始化为非静态类成员

c++ - 将警告转换为错误