hi i'm currently in need of a quit option

i have something like for example click 2 for quit but i don't know how to make a command for it, could someone please help me

Dani AI

Generated

The thread shows the typical options for a "quit" menu: a library call to terminate the process (noted by ) and a lower-level immediate stop (mentioned by ). For everyday console/menu programs a cleaner pattern is a structured shutdown: break out of the main loop and let main return so stack unwinding and object destructors perform normal cleanup.

A simple pattern looks like this:

int main() {
    bool running = true;
    while (running) {
        int choice;
        std::cin >> choice;
        switch (choice) {
            case 1: /* do work */ break;
            case 2: running = false; break; // quit option
        }
    }
    // normal cleanup via destructors / RAII happens here
    return 0;
}

Notes and cautions: immediate termination functions end the process without the same stack-unwinding guarantees, so file streams, locks, and local objects may not be cleaned up the usual way; registered exit handlers behave differently depending on which termination method is used. Programs that spawn threads should join or detach them before shutdown, and long-lived resources are safest when managed by RAII. More on program termination semantics and on destructor/cleanup behavior can be found in the C++ reference documentation: std::exit and termination behavior and destructors / RAII rules.

Recommended Answers

All 4 Replies

_exit(0);

problem solved thanks alot !!

please mark as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.