C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

C++ Source Code


Welcome to Dream.In.Code
Become a C++ Expert!

Join 300,293 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,131 people online right now. Registration is fast and FREE... Join Now!





Getting Current Directory

Getting the current directory. TAKEN FROM BORLAND C++ HELP

Submitted By: born2c0de
Actions:
Rating:
Views: 71,480

Language: C++

Last Modified: March 2, 2005

Snippet


  1. // The Code is Borland's, I just modified it
  2. // to make it Standard C++
  3.  
  4. #include <direct.h> // for getcwd
  5. #include <stdlib.h>// for MAX_PATH
  6. #include <iostream> // for cout and cin
  7.  
  8. using namespace std;
  9.  
  10. // function to return the current working directory
  11. // this is generally the application path
  12. void GetCurrentPath(char* buffer)
  13. {
  14. getcwd(buffer, _MAX_PATH);
  15. }
  16.  
  17. int main()
  18. {
  19.  
  20. // _MAX_PATH is the maximum length allowed for a path
  21. char CurrentPath[_MAX_PATH];
  22. // use the function to get the path
  23. GetCurrentPath(CurrentPath);
  24.  
  25. // display the path for demo purposes only
  26. char temp[_MAX_PATH];
  27. cout << CurrentPath << endl;
  28. cout << "Press Enter to continue";
  29. cin.getline(temp,_MAX_PATH);
  30. return 0;
  31. }

Copy & Paste


Comments


ukpjava 2008-03-02 22:37:07

Thank u very much.as i am a biginer it is very helpful for me


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month