-4
void phonebookmenu() {
    phonebook ph;

    string str;

    cin.ignore();
    cout << "PH> ";
    getline(cin, str); //Input from user.

    string buf; // Have a buffer string.
    stringstream ss(str); // Insert the string into a stream.
    vector<string> tokens; // Create vector to hold the words.

    while (ss >> buf){
        tokens.push_back(buf); //Adds all the words inside the vector.
    }

    while (true){
    if (tokens[0] == "add"){
            ph.add(tokens[1],tokens[2]);
    }
    else if(tokens[0] == "lookup"){
            ph.lookup(tokens[1]);
    }
    else if(tokens[0] == "change"){
            ph.change(tokens[1],tokens[2]);
    }
    else if(tokens[0] == "alias"){
            ph.alias(tokens[1],tokens[2]);
    }
    else if(tokens[0] == "quit"){

            //Return to the "Main-menu"
    }

    else{
        cout << "Invalid input" << endl;
    }
}

So i'm calling this menu from a "Main-menu" but after i have input something like "Add peter 123" it does the function then returns to the "Main-menu" which i don't want. It's supposed to go back to

cout << "PH> ";  

So i can continue to make operations.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Widdin
  • 47
  • 1
  • 4

1 Answers1

0

The loop is not around the cout/input/determine/do something logic. It's only around the determine/do something. Move the while to before the cout and see what happens. Be sure to mark the answer that helps most as an answer.

Barniferous
  • 93
  • 11