C + + relative and absolute paths

Source: Internet
Author: User

Learning memo turn from: http://www.cnblogs.com/vranger/p/3820783.html

Computer hard disk under the E-drive folder "test", "Test" under the sub-folder "file", "File" under the sub-folder "Data",

Computer Explorer displays the directory E:\test\file\data

Current Path E:\test\file

===================================================

1. Relative path, with forward slash '/'

1.1 Up-level directory pointing

./indicates the current path, equivalent to E:\test\file

.. /represents the upper-level path of the current path, equivalent to E:\test

.. /.. /indicates the first-level path on the current path, equivalent to E:

More pointers to ancestor paths and so on.

1.2 Pointing down a level directory

The./data represents the next-level path in the current path, equivalent to E:\test\file\data

The./data/xxx represents the lower-level path of the current path, equivalent to E:\test\file\data\xxx

More representations of the paths pointing down and so on.

2. Absolute path, with backslash ' \ '

E:\test

E:\test\file

E:\test\file\data

Relative path and absolute path usage in 3.c\c++ programming

In the C language, the backslash ' \ ' represents an escape character, so the absolute path needs to be represented as follows

FILE * FP;

fp = fopen ("E:\\test\\file\\data\\d.txt", "R");

It can also be represented by a relative path, not by the escape character limit:

FILE * FP;

fp = fopen ("E:/test/file/data/d.txt", "R");

Or, under current path E:\test\file, relative paths are represented as

FILE * FP;

fp = fopen ("./data/d.txt", "R");

Note: To add direct.h to the header file when using relative and absolute paths

C + + relative and absolute paths

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.