#include // for chdir, ... #include // for errno #include // for strerror C++ #include // for strerror C++ //#include // for strerror c #include #include using namespace std; void PrintCurrentDir(void); void ChangeTo(const string & newDir); int main() { string newDir; while (newDir != "QUIT") { PrintCurrentDir(); getline(cin,newDir); if (newDir != "QUIT") { ChangeTo(newDir); } } return 0; } void PrintCurrentDir(void){ char * name; name = get_current_dir_name(); if (nullptr != name) { cout << "[ " << name << " ] >"; cout << flush ; free(name); } else { perror("\tget_current_dir_name failed:"); cerr << "\tThe error number is " << errno << endl; cerr << "\tAnd the string is " << strerror(errno) << endl; } return; } void ChangeTo(const string & cmd){ if (0 != chdir(cmd.c_str())) { perror("\tchdir failed:"); cerr << "\tThe target was " << cmd << endl; cerr << "\tThe error number is " << errno << endl; cerr << "\tAnd the string is " << strerror(errno) << endl; } return; }