File Path: forward slash and backslash
Forward slash (/), also known as left slash "/"; Backslash, also known as the right slash, with the symbol "\".
The file path can be divided into absolute and relative paths:
Absolute path representation is relatively easy, for example:
Pdummyfile = fopen ("d :\\ vctest \ gltexture \ texture \ dummy.bmp", "rb ");All paths starting with the drive letter are provided. Note that "\"Use double slashes" \ ". The default directory accessed by the VC project is the project directory,
The relative path has the following forms:
Pdummyfile = fopen ("dummy.bmp", "rb"); the BMP file is under the VC project directory, which is the same as the DSW file.
Pdummyfile = fopen (".. \ texture \ dummy.bmp "," rb "); indicates that the BMP file is in texture, therefore, the path is to exit the project directory and then access the BMP file in the texture directory. ".." Indicates to return to the upper-level directory (parent directory) of the current directory)
Pdummyfile = fopen (". \ texture \ dummy.bmp "," rb "); indicates that the BMP file is in the texture subdirectory of the project directory. "indicates the current default directory, that is, the VC project directory, and then access the file in its subdirectory texture
It is worth noting that for relative paths, "\" in the path representation must also use double slashes \\. In C ++, \ is an escape character. It represents a \ character, just as \ n represents a carriage return.
Therefore, C ++Path Name in:
D: \ matcom45 \ doc \ Users \ _ themes \ m. dat
Should be:
Cstring filename = _ T ("d :\\ matcom45 \ doc \ Users \ _ themes \ m. dat ");Or
Cstringfilename = _ T ("D:/matcom45/doc/users/_ themes/M. dat ");
"./"Adding and not adding are the same,The current directory.
"../"Indicates the parent directory of the current directory,That is, the current parent directory.
In Unix/LinuxThe path is separated by a forward slash (/), for example, "/home/huaow ";
In Windows, the path is separated by a backslash (\), for example, "C: \ WINDOWS \ SYSTEM ".
Sometimes we can see the path format "C: \ Windows \ System", that is, using two backslash to separate the paths, this method is often seen in network applications or programming. In fact, the above path can be replaced by "C:/Windows/system" without errors. However, if you write "C: \ WINDOWS \ SYSTEM", there may be various strange errors. The cause of the above problem should be analyzed from the aspect of string parsing. Anyone who has learned programming should know that when outputting a string in C, If You Want To output a line feed, add the '\ n' sign. Similarly, output a tab, '\ T' is added, that is, the backslash ("\") is used to combine the characters following it and convert them to other characters. According to this principle, if you want to output double quotation marks ('"'), you need to enter '\"' to correctly write the string containing double quotation marks into the memory. What if you want to enter a backslash? It's easy. Just press.
Some people may have noticed that, if the path string "C: \ WINDOWS \ SYSTEM" is handed to the C compiler for compilation, the string actually written into the memory does not contain the Backslash "\", and even the letters that follow the backslash are escaped into other characters. If you call it again, the problem may occur.
String Parsing is not limited to CCompilers, Java compilers, parsing of some configuration files, Web servers, and so on all encounter this problem. Because the traditional Windows system uses the path separation form of a single slash, as a result, unnecessary errors may occur when parsing the file path, so there is a form of separating paths with double Backslash. No matter whether the parsing engine parses the backslash into an escape character or not, the final result obtained in the memory is "\", and no problem will occur.