How to initialize a string with not using escape?

P

Peng Yu

Suppose I have backslash in the following code, backslash will be
interpreted as the escape character to change the meaning of the next
character. But I don't what such changes. Besides using double
backslashes, is there a way make C++ compiler take backslash
literally?

std::string s="\a\&^";
 
R

Richard

[Please do not mail me a copy of your followup]

red floyd <[email protected]> spake the secret code
[Please do not mail me a copy of your followup]

Peng Yu <[email protected]> spake the secret code
[...] Besides using double
backslashes, is there a way make C++ compiler take backslash
literally?

Not in a string literal, no.

Well, in C++0x, he could use a raw string literal, couldn't he?

Didn't know that was in C++0x. Still, considering that it isn't in gcc
or VC++, I don't know that its very useful (yet).

<http://www.aristeia.com/C++0x/C++0xFeatureAvailability.htm>
 
J

Jorgen Grahn

red floyd said:
Peng Yu <[email protected]> spake the secret code
<1da334ed-373c-47ba-8025-bb56176f1...@c33g2000yqm.googlegroups.com> thusly:

[...] Besides using double
backslashes, is there a way make C++ compiler take backslash
literally?

Not in a string literal, no.

Well, in C++0x, he could use a raw string literal, couldn't he?

Didn't know that was in C++0x. Still, considering that it isn't in gcc
or VC++, I don't know that its very useful (yet).

<http://www.aristeia.com/C++0x/C++0xFeatureAvailability.htm>

Also worth keeping in mind is that *when* such a thing becomes
available, it takes years or decades until many of us can use them.

Earlier today, I had to rewrite a piece of C99 code (ten years ago) as
C89 (twenty years ago) because at least one of our compilers hadn't
heard of declaring variables at any place except the top of a block.
Very annoying!

/Jorgen
 
M

Michael Tsang

Jorgen said:
red floyd <[email protected]> spake the secret code
On Jun 13, 8:52 pm, (e-mail address removed) (Richard) wrote:
Peng Yu <[email protected]> spake the secret code
<1da334ed-373c-47ba-8025-bb56176f1...@c33g2000yqm.googlegroups.com>
thusly:

[...] Besides using double
backslashes, is there a way make C++ compiler take backslash
literally?

Not in a string literal, no.

Well, in C++0x, he could use a raw string literal, couldn't he?

Didn't know that was in C++0x. Still, considering that it isn't in gcc
or VC++, I don't know that its very useful (yet).

<http://www.aristeia.com/C++0x/C++0xFeatureAvailability.htm>

Also worth keeping in mind is that *when* such a thing becomes
available, it takes years or decades until many of us can use them.

Earlier today, I had to rewrite a piece of C99 code (ten years ago) as
C89 (twenty years ago) because at least one of our compilers hadn't
heard of declaring variables at any place except the top of a block.
Very annoying!

/Jorgen

Are you writing a compiler? If not, just tell the user to compile a C99
compiler.
 
J

Jorgen Grahn

Jorgen Grahn wrote: ....


Are you writing a compiler? If not, just tell the user to compile a C99
compiler.

Welcome to the real world! If you have never got stuck in a situation
like that it can be hard to understand, but combine these:

- lack of time to do "cosmetic" work
- fear of regressions in rarely-used code which is hard to test
- semi-obsolete embedded systems
- ... with semi-obsolete toolchains
- ... which are shared with other projects
- inflexible build systems with hardcoded dependencies

and it's not really /that/ surprising that you end up with an ancient
dialect of (in this case) C.

/Jorgen
 

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
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top