C++ || Snippet – How To Display The Current Working Directory

Print Friendly, PDF & Email

The following is sample code which demonstrates how to display the current working directory of the program when its properties were initialized.

If you are a system admin, this has a similar effect to the “echo %CD%” Windows Shell command or the “pwd” Unix/Linux terminal command, which essentially displays the current working directory the program is located at.


QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output
Note: This was compiled using a Windows computer

This file is located in directory:

C:UsersAdminDesktop

Please press ENTER to continue...

Leave a Reply