User input chdir c++

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2007
Posts: 55
Reputation: darren2005 is an unknown quantity at this point 
Solved Threads: 2
darren2005's Avatar
darren2005 darren2005 is offline Offline
Junior Poster in Training

User input chdir c++

 
0
  #1
Nov 8th, 2008
I'm very new at C++ and would like to know how I would change a directory via user input? This will be a Win32 Project and not a Win32 application.

I know I can use (as standard - and without user input) the chdir("\\dir"); - but how do I use this with user input?

Thanks in advance!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: User input chdir c++

 
0
  #2
Nov 8th, 2008
usethe string header so you can get the path from the user then pass it to chdir like this

  1. chdir(path.c_str());

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 55
Reputation: darren2005 is an unknown quantity at this point 
Solved Threads: 2
darren2005's Avatar
darren2005 darren2005 is offline Offline
Junior Poster in Training

Re: User input chdir c++

 
0
  #3
Nov 10th, 2008
Thanks for your reply!!

Sorry if I am being thick, but is this correct (some of the script has been removed)?

#include <string.h>

using namespace std;

string entry;

cout << "1. Enter FULL PATH to directory: ";
cin >> entry;

chdir(path.entry_str());

cin.get();

	return 0;
}

Thanks again for your help!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: User input chdir c++

 
0
  #4
Nov 10th, 2008
This should help you out

http://msdn.microsoft.com/en-us/libr...e1(VS.80).aspx
I would read that but this is how to use it anyway

  1. #include <string>
  2. #include <direct.h>
  3.  
  4. using namespace std;
  5.  
  6. int main(void){
  7.  
  8. string hello;
  9.  
  10. hello = "C:\\";
  11.  
  12. _chdir(hello.c_str());
  13.  
  14. cin.get();
  15. return 0;
  16. }

Chris
Last edited by Freaky_Chris; Nov 10th, 2008 at 2:44 pm.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 55
Reputation: darren2005 is an unknown quantity at this point 
Solved Threads: 2
darren2005's Avatar
darren2005 darren2005 is offline Offline
Junior Poster in Training

Re: User input chdir c++

 
0
  #5
Nov 10th, 2008
Hi,

Thank you very much for that. It now works!!!!

Using:

string user;
string entry;

cout << "2. Enter FULL PATH to DIR: ";
cin >> entry;

user = entry;

_chdir(user.c_str());

Thanks for your help!!!!!!!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC