如何在 GCC 4.5 中使用 C++0x 原始字符串?

Posted

技术标签:

【中文标题】如何在 GCC 4.5 中使用 C++0x 原始字符串?【英文标题】:How do you use C++0x raw strings with GCC 4.5? 【发布时间】:2010-06-05 08:18:02 【问题描述】:

这个页面说 GCC 4.5 有 C++ 原始字符串文字:

http://gcc.gnu.org/projects/cxx0x.html

但是当我尝试使用此页面中的语法时:

http://www2.research.att.com/~bs/C++0xFAQ.html#raw-strings

#include <iostream>
#include <string>

using namespace std;

int main()

    string s = R"[\w\\\w]";


我收到此错误:

/opt/local/bin/g++-mp-4.5 -std=gnu++0x -O3 rawstr.cc -o rawstr rawstr.cc:9:19:错误:原始字符串分隔符中的无效字符“\” rawstr.cc:9:5: 错误:程序中出现“R”错误

原始字符串的正确语法是什么?

【问题讨论】:

【参考方案1】:

试试

R"(\w\\\w)";

n3077 中的分隔符 […] 更改为 (…)

【讨论】:

以上是关于如何在 GCC 4.5 中使用 C++0x 原始字符串?的主要内容,如果未能解决你的问题,请参考以下文章