DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   User input chdir c++ (http://www.daniweb.com/forums/thread156124.html)

darren2005 Nov 8th, 2008 6:00 pm
User input chdir c++
 
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! :)

Freaky_Chris Nov 8th, 2008 7:00 pm
Re: User input chdir c++
 
usethe string header so you can get the path from the user then pass it to chdir like this

chdir(path.c_str());

Chris

darren2005 Nov 10th, 2008 2:20 pm
Re: User input chdir c++
 
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!

Freaky_Chris Nov 10th, 2008 2:42 pm
Re: User input chdir c++
 
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

#include <string>
#include <direct.h>

using namespace std;

int main(void){
   
    string hello;
   
    hello = "C:\\";
   
    _chdir(hello.c_str());
   
    cin.get();
    return 0;
    }

Chris

darren2005 Nov 10th, 2008 3:28 pm
Re: User input chdir c++
 
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!!!!!!!


All times are GMT -4. The time now is 9:17 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC