views:

158

answers:

4
std:string str("text1\; text2\;");

How come VS2005 says ; unrecognized character escape sequence.

Please advise, thanks.

+3  A: 

Just put the semicolon with no backslash:

std::string str("text1; text2;");
Jesse Beder
Don't forget the `std::` prefix missing a colon.
Pieter
+4  A: 

There is no need to escape semicolons

Victor Hurdugaci
+12  A: 

Because this is wrong:

std:string str("text1\; text2\;");

This is correct:

std::string str("text1; text2;");

TWO colons after std.

PeterK
+2  A: 

Semicolons have absolutely no significance in C strings; they're just normal characters there. If you need to put a backslash in the string because something later requires it, it's the backslash that needs the backslash in front.

std::string str("text1\\; text2\\;");

That's because \; is not a recognized escape sequence in C++; the compiler rightly wants to know what on earth you're talking about when you put that in.

Donal Fellows