Replace '\' with '/' in c++

Sep 27, 2012 at 7:13am
Hi,

How can i replace the all the occurrence of '\' character with '/' in a string.

if i give like,

url.replace(url.begin() , url.end() , '\' , '/' );

its shows error.

error C2001: newline in constant
error C2146: syntax error : missing ')' before identifier 'cout'

Thanks,
Last edited on Sep 27, 2012 at 7:14am
Sep 27, 2012 at 7:21am
You can't write '\' - the backslash indicates an escape sequence, not the backslash character. You need to double it up, like this:

url.replace(url.begin() , url.end() , '\\' , '/' );
Topic archived. No new replies allowed.