#include #include using namespace std; const int BUF_SIZE = 100; int main() { string command; string dir; char current[BUF_SIZE]; if (NULL != getcwd(current, BUF_SIZE)) { cout << "The current directory is " << current << endl; } else { perror("getcwd"); } cout << "Enter a command => "; cin >> command; getline(cin,dir); while (command != "QUIT") { if (command == "UP") { if (-1 == chdir("..")) { perror ("chdir, can't go UP"); } } else if (command == "GO") { // need to trim. while (isblank(dir[0]) ) { dir = dir.substr(1,dir.size()); } if (-1 == chdir(dir.c_str())) { perror ("chdir"); cerr << "Can't change to " << dir << endl; } } else { cout << "Unknown command, " << command << endl; cout << "\tUP, GO, QUIT" << endl; } if (NULL != getcwd(current, BUF_SIZE)) { cout << "The current directory is " << current << endl; } else { perror("getcwd"); } cout << "Enter a command => "; cin >> command; getline(cin,dir); } return 0; }