By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

Double BackSlashes

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a

"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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
Thank you guys!
You realy helped me.
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.