Sign in to follow this  
derek7

what is the different between the \ and /

Recommended Posts

when I use directory and file in programming I find both / and \ work.just use \\ instead of \. so what is the different else between the \ and / ?

Share this post


Link to post
Share on other sites
There no real difference, "/" just doesn't need an escape character.
I think "\\" doesn't work for Unix type file systems, but I'm not sure.

Share this post


Link to post
Share on other sites
The backslash ('\') is used as an escape character in C and C++ , so to represent the backslash itself you'll need to write '\\'. MS decided do use the backslash as primary path seperator, while all other (modern) OS' use the forward slash ('/').
So when programming for Windows only, the difference between both separators mainly is safety, since typos are less common while using forward slashes (remember the escape-character thing).
If your code is intended to compile on more than just the windows-platform, it is essential to use the forward slash as path separator, since most other OS' use it exclusively.

HTH,
Pat

Share this post


Link to post
Share on other sites
I think in the old days, you needed to use "\" for paths in Windows, and "/" for paths in Unix. But now Windows just lets you use either, for compatibility with unix-style paths.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In the Olde Days?! Damn you young whipper snappers! :)


I believe that the forward slash is also a standard in web urls (e.g. when referring to directory paths in .html files)


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this