468,737 Members | 2,589 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,737 developers. It's quick & easy.

Double BackSlashes

Hello!
I need to translate file destination name with one backslashes
"c:\program files\directory\file.txt"
to string containing double backslashes
"c:\\program files\\directory\\file.txt"
If there is a nativi function on C++, or any algolithms I'd be glad
to know about them.
Thank you
Jul 19 '05 #1
6 22710
Mikheil wrote:
I need to translate file destination name with one backslashes
"c:\program files\directory\file.txt"
to string containing double backslashes
"c:\\program files\\directory\\file.txt"
If there is a nativi function on C++, or any algolithms I'd be glad
to know about them.


Why not translate it to
"c:/program files/directory/file.txt"?

This should be far easier to accomplish and works too on any
Windows OS. (ok, Im not sure about 3.11)

Otherwise you could use std::string.find and insert (or replace)

(untested):

std::string temp = "c:\program files\directory\file.txt";

for (int i = 0; i < temp.length(); ++i)
if (temp[i] == '\\')
{
temp.insert(i, 1, '\\');
++i; // Skip inserted char
}
cya

Christoph

Jul 19 '05 #2

"Mikheil" <mi****@global-erty.net> wrote in message
news:d8**************************@posting.google.c om...
Hello!
I need to translate file destination name with one backslashes
"c:\program files\directory\file.txt"
to string containing double backslashes
"c:\\program files\\directory\\file.txt"
If there is a nativi function on C++, or any algolithms I'd be glad
to know about them.
Thank you


I think you are confused, a double backslash is just the way you write a
single backslash in C++.

"\\" - this string is a single backslash.

"\\\\" - this string is a double backslash.

If you have a string in memory with single backslashes then it will work to
open a file. If you have a string in your program code, then you *type*
double backslashes. There is no need to replace single backslashes with
double blackslashes programmatically.

john
Jul 19 '05 #3

"Mikheil" <mi****@global-erty.net> wrote in message
news:d8**************************@posting.google.c om...
Hello!
I need to translate file destination name with one backslashes
"c:\program files\directory\file.txt"
This string does not have any backslashes

\p, \d are illegal characters, \f is the form feed character.
to string containing double backslashes
"c:\\program files\\directory\\file.txt"
This string has three single backslashes, \\ is the way you write a single
backslash character. \\\\ is a double backslash character.
If there is a nativi function on C++, or any algolithms I'd be glad
to know about them.
Thank you


john
Jul 19 '05 #4
Christoph Rabel wrote:
John Harrison wrote:
I don't think that will work. There are no blackslashes in your original
string.


Hmm, I can think of at least one case where it is necessary to write
double backslashes out to a file.


Oops, misunderstood you. Of course it should be:

std::string temp = "c:\\program files\\directory\\file.txt";

thx for correcting me.

Christoph

Jul 19 '05 #5
Andrey Balaguta wrote:
Christoph Rabel wrote:
Why not translate it to
"c:/program files/directory/file.txt"?

This should be far easier to accomplish and works too on any
Windows OS. (ok, Im not sure about 3.11)
This will work?


Probably. Depends on your needs.
Its most of the time better to use / then \. Far less troubles,
especially if you want to port the stuff one day.
What functions with? Will this work with stdlib?


I dont understand where your questions aim. Maybe you could try to
explain what you want to achieve. As John pointed out its most of the
time not necessary to change anything.

If \ or / works is OS specific, all std-functions only invoke the OS
functions and give them the paths. So, if the OS knows how to interpret
it, then it works.

mfg

Christoph

Jul 19 '05 #6
Thank you guys!
You realy helped me.
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by sinister | last post: by
7 posts views Thread by Margaret MacDonald | last post: by
5 posts views Thread by Aloysio Figueiredo | last post: by
3 posts views Thread by Stef Mientki | last post: by
3 posts views Thread by =?Utf-8?B?cmFuZHkxMjAw?= | last post: by
23 posts views Thread by dkirkdrei | last post: by
7 posts views Thread by JohnF | last post: by
6 posts views Thread by Joseph Stateson | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.