mardi 27 avril 2021

C++ feed cin enter?

I am the owner of: C++ Signal Handlers output doesn't appear? but lost access to my account (used temp email which is my fault).

Regarding the same question, in case ctrl+z was pressed how can I feed Enter to cin to make my bash behave as expected instead of waiting for the user to press enter.

For reference I have:

if (signal(SIGTSTP, ctrlZHandler) == SIG_ERR) {
    perror("smash error: failed to set ctrl-Z handler");
}

SmallShell &smash = SmallShell::getInstance();
while (keep_running) {
    std::cout << "smash> ";
    std::string cmd_line;
    std::getline(std::cin, cmd_line);
    smash.executeCommand(cmd_line.c_str());
}


void ctrlZHandler(int sig_num) {
    //SIGTSTP-18
    cout << "smash: got ctrl-Z" << endl;
    SmallShell::route_signal(sig_num);
}

Aucun commentaire:

Enregistrer un commentaire