CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2000
    Posts
    1,471

    A question regarding forward slash and back slash

    As we know in unix/linux, forward slash is always used for directory and in windows back slash is used for directory instead. On the other hand, I noticed that forward slash can be also used for directory in windows. But it doesn't always work properly. If I write a program that can be run in both linux and windows, what is best way to handle forward/back slash? Thanks for your inputs.

  2. #2
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: A question regarding forward slash and back slash

    Quote Originally Posted by dullboy View Post
    But it doesn't always work properly.
    In what circumstances doesn't it work properly?
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: A question regarding forward slash and back slash

    Quote Originally Posted by dullboy View Post
    On the other hand, I noticed that forward slash can be also used for directory in windows.
    A forward slash can be used in any standard C++ or C file I/O function as the directory separator.

    For specific Windows API functions, then you must be careful as to the direction of the slashes.

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: A question regarding forward slash and back slash

    note: some windows API functions support forward slashes as alias for backslash, some don't
    it isn't typically documented, so it'll require testing. To make matters worse, things may differ from one version of windows to another as well.

    Even some of the functions that do support it, will return paths with backslashes.

    iirc, there's even a few oddball cases where the input string is converted to backslashes, even though the input parameter in the API is defined as a const-string. This could be a critical problem for some apps. This is a fatal error if said string is in a readonly section.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured