multiple lines declaration

S

sam

Hi,

The following multiple lines declaration failed.
How can I declare it in C/C++ syntax?

string regex_parser =
"(go)\ +on\ +\$(\S+) // keyword (1) ext_if (2)
\ +from\ +\$(\S+) // int_net (3)
\ +to\ +\$(\S+) // dest(any) (4)
\ +->\ +\(\$(\S+)\)$";


the error is:
myparser.cpp:9: error: missing terminating " character
myparser.cpp:10: error: stray '\' in program
myparser.cpp:10: error: stray '\' in program
....

where line #9 is "(go)\ +on\ +\$(\S+)"

Thanks
Sam
 
V

Victor Bazarov

sam said:
The following multiple lines declaration failed.
How can I declare it in C/C++ syntax?

string regex_parser =
"(go)\ +on\ +\$(\S+) // keyword (1) ext_if (2)
\ +from\ +\$(\S+) // int_net (3)
\ +to\ +\$(\S+) // dest(any) (4)
\ +->\ +\(\$(\S+)\)$";


the error is:
myparser.cpp:9: error: missing terminating " character
myparser.cpp:10: error: stray '\' in program
myparser.cpp:10: error: stray '\' in program
...

where line #9 is "(go)\ +on\ +\$(\S+)"

String literals shall not contain newline characters. Close
every line with a double quote and the parts will be concatenated:

string regex_parser =
"one part" // some comment
"other part";

V
 
A

Andre Caldas

By the way,
string regex_parser =
"(go)\ +on\ +\$(\S+) // keyword (1) ext_if (2)
\ +from\ +\$(\S+) // int_net (3)
\ +to\ +\$(\S+) // dest(any) (4)
\ +->\ +\(\$(\S+)\)$";

The charactere \ is a escape charactere. You need to write \\ if you
want it to be on the string.
 
S

sam

Andre said:
By the way,



The charactere \ is a escape charactere. You need to write \\ if you
want it to be on the string.

I have added " and \ to fix the problem, but still haven't tried a real
example yet. I hope this parser works as it supposed to be.

Thanks
Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,663
Latest member
josh5959

Latest Threads

Top