Code Snippets

  

C++ Source Code


Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 86,467 C++ Programmers. There are 1,283 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a C++ Expert
Powered by LivePerson.com

Register to Make This Box Go Away!


Getting Current Directory

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

Submitted By: born2c0de
Actions:
Rating:
Views: 32,905

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!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month