Avatar of titanium0203
titanium0203

asked on 

How to insert "\\" in vc6 in c:\abc\def\aaa.bmp

Hi,

How can I insert "\\" in my absolute path?

Thanks
C++C

Avatar of undefined
Last Comment
Janusz Czopowik
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Do you mean how to insert back-slashes in a string literal? Just put two consecutive back slashes each place in the string you want one.

char path[] = "C:\\abc\\def\\aaa.bmp";

Or...

char path[] = "\\\\server\\sharedFolder\\aaa.bmp";
Avatar of titanium0203
titanium0203

ASKER

Hi,

currently my apps return with a single back slash, is there any function
that can automatically conver it to double back slash.

thanks
ie your apps you mean that return value is string, than don't need nothing.
should work perfectly
char path[] = "C:\\abc\\def\\aaa.bmp";
is needed just wen you write in the code to convert it to string, but once converted that become
C:\abc\def\aaa.bmp
and no changes needed

but  you can do that if you want be replacing
string x = "C:\abc\def\aaa.bmp";
string _new = x.Replace("\\","\\\\");
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
All the reason for a double backslash is that backlash serves as an escape character in C/C++.
It enables inserting special (control) characters into a string literal. For example: \n means line feed \r is a carriage return, \t is a tab.
Therefore if you want backslash to be interpreted as backslash you have to use two: escape (\) and real (\) ending up with \\.
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo