By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 898 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

multiple lines declaration

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
sam wrote:
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
Jul 23 '05 #2

P: n/a
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.
Jul 23 '05 #3

P: n/a
sam
Andre Caldas wrote:
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.


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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.