Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use C++0x raw strings with GCC 4.5?

Tags:

c++

c++11

g++

This page says that GCC 4.5 has C++ raw string literals:

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

But when I try to use the syntax from this page:

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]";

}

I get this error:

/opt/local/bin/g++-mp-4.5 -std=gnu++0x -O3 rawstr.cc -o rawstr
rawstr.cc:9:19: error: invalid character '\' in raw string delimiter
rawstr.cc:9:5: error: stray 'R' in program

What is the right syntax for raw strings?

like image 704
Rob N Avatar asked Jun 05 '10 08:06

Rob N


People also ask

What is a raw string in C?

A rawstring is a string literal (prefixed with an r) in which the normal escaping rules have been suspended so that everything is a literal.

What is raw string in programming?

A raw string in programming allows all characters in a string literal to remain the same in code and in the material, rather than performing their standard programming functions. Raw strings are denoted with the letter r, or capital R, and might look something like this: R “(hello)”


1 Answers

Try

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

The delimiters […] were changed to (…) in n3077.

like image 57
kennytm Avatar answered Nov 07 '22 08:11

kennytm