First thing I will say is, in C++ you don't actually need to ever use a goto, and using it to loop is a bit underdevoloped IMHO. Do a look up on try and catch statements. They are what you use instead of goto's.
Second why don't use just use include <string>?
A nice way you can do that without your goto is.
Code:#include <iostream> #include <string> int main() { string com1; cout << "Enter a Command" << endl; cout << "Enter help for list of commands" << endl; cin.get(com1); while(com != "exit") { if(com1 == "help") { cout << "commands" << endl; cout << "cd" << endl; cout << "ls" << endl; cout << "exit" << endl; } else if (com1 == "ls") { cout << "bugreport" << endl; cout << "landing" << endl; cout << "watergate" << endl; cout << "WOMDIRAQ" << endl; } else if (com1 == "cd ..") { cout << "/root:"; } else if (com1 == "exit") { break; } else { cout << "Command not found" << endl; } cin >> com1; } }




Reply With Quote