Difference between forward and backslash [duplicate]

旧城冷巷雨未停 提交于 2019-11-26 18:26:46

问题


What is the difference in using a forward slash and backslash in navigating file systems. Also what is the difference between ./ and ../?


回答1:


Well, in most languages backslashes need to be escaped in string literals, slashes do not. Further backslashes only work on Windows, while slashes work pretty much everywhere.

On the other hand, when passing path names as arguments to Windows programs, using slashes might not work because many Windows programs use slashes to signify command line flags, so you need to use backslashes.

On . vs. ..: . is the current directory, .. is the parent directory.




回答2:


Microsoft operating systems (e.g. DOS and Windows) use backslashes (\), UNIX-based operating systems (e.g. Linux) use slashes (/).

The dot (.) means the current working directory, it's like saying "here". The double dot (..) means the parent directory.




回答3:


The difference between slash and backslash in Windows are from my tests at least non-existing, but I believe that in earlier editions they used backslash. UNIX systems uses slash.

The difference between ./ and ../ is that ./ represents the position in the hierarchy where you are standing while ../ is the parent directory.




回答4:


Backslash is used for:

File names in DOS and Windows, e.g. D:\documents\office, C:\java\jdk escape sequences in C, Unix, and other languages/systems that borrow the same syntax (C++, Java, etc.). For example, \n means newline and \t means tab.

Forward slash is used for:

  • File names on Unix (and Mac OS X, since it is derived from Unix), e.g. /cs/student/jsmith/cs8/lab00, /Users/Shared/cs8/cTurtle.py.
  • Web addresses (URLs), such as http://www.cs.ucsb.edu/~pconrad/cs8.
  • Dividing in many programming languages, e.g. battingAvg = hits / atBats;


来源:https://stackoverflow.com/questions/6946746/difference-between-forward-and-backslash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!