system command

E

Eliseo

in a system command when you want to do something with directories you
are forced to type \\ unstid of just one (ex. system("md
c:\\newdir");) is there any way I can avoid this, I am making a VB
program that interacts with this C++ program and needs to have those
off. Thank alot. Please email me an answer if possible
([email protected]).
 
V

Victor Bazarov

Eliseo said:
in a system command when you want to do something with directories you
are forced to type \\ unstid of just one (ex. system("md
c:\\newdir");) is there any way I can avoid this, I am making a VB
program that interacts with this C++ program and needs to have those
off. Thank alot.

What's the problem you're experiencing? The doubling of the backslash
is only necessary in C++ _source_code_ so that the compiler converts
them into a _single_ backslash. You can confirm that by looking at
the resulting executable using any hex editor. The "md c: ..." string
will have only single backslashes in it.
Please email me an answer if possible
([email protected]).

Not possible.

Victor
 
M

Mike Wahler

Eliseo said:
in a system command

Note that C++ has no 'commands'. 'system()' is a
standard library function.
when you want to do something with directories

The syntax you're asking about has nothing to do with
directories, but with 'escaped' characters, i.e. those
which cannot be directly expressed in a source code with
a single character. E.g. a newline character is expressed
as '\n', a tab character as '\t', etc. Since the backslash
('\') character is being used for this 'escape' character,
we need a way to express the backslash character itself.
This is done with the 'escape' character (the backslash),
followed by another backslash.

you
are forced to type \\ unstid of just one

Only in your source code.
(ex. system("md
c:\\newdir");) is there any way I can avoid this, I am making a VB
program that interacts with this C++ program and needs to have those
off.

They're already 'off'. Your string itself contains
no 'extra' backslashes.

When you write e.g. "C:\\newdir" in your C++ source
text, this expresses the string "C:\newdir". There's
no 'extra' backslash except in your C++ source code.


Try this example:

#include <iostream>

int main()
{
std::cout << "c:\\newdir" << '\n';
return 0;
}

Note that the output is:

c:\newdir


Thank alot. Please email me an answer if possible

This is a public forum. Post here, read here.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top