system command

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eliseo

    system command

    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
    (eliseogonzalez @hotmail.com).
  • Victor Bazarov

    #2
    Re: system command

    "Eliseo" <eliseogonzalez @hotmail.com> wrote...[color=blue]
    > 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.[/color]

    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.
    [color=blue]
    > Please email me an answer if possible
    > (eliseogonzalez @hotmail.com).[/color]

    Not possible.

    Victor


    Comment

    • Mike Wahler

      #3
      Re: system command

      Eliseo <eliseogonzalez @hotmail.com> wrote in message
      news:ab04fba6.0 309150917.391e0 8dc@posting.goo gle.com...[color=blue]
      > in a system command[/color]

      Note that C++ has no 'commands'. 'system()' is a
      standard library function.
      [color=blue]
      > when you want to do something with directories[/color]

      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.

      [color=blue]
      > you
      > are forced to type \\ unstid of just one[/color]

      Only in your source code.
      [color=blue]
      > (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.[/color]

      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


      [color=blue]
      > Thank alot. Please email me an answer if possible[/color]

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

      -Mike



      Comment

      Working...