Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately you didn't really show the code you are using but rather some pseudo code. Thus, it is hard to tell what you are actually trying to do. From the description of your problem and your pseudo code I suspect, however, that the root of the problem is that you don't check your inputs and don't restore the stream to a reasonably good state! To read the menu selection you probably want to use code akin to this:</p> <pre><code>int choice(0); if (std::cin &gt;&gt; choice) { deal with the choice of the menu here } else if (std::cin.eof()) { // we failed because there is no further input: bail out! return; } else { std::string line; std::cin.clear(); if (std::getline(std::cin, line)) { std::cout &lt;&lt; "the line '" &lt;&lt; line &lt;&lt; "' couldn't be procssed (ignored)\n"; } else { throw std::runtime_error("this place should never be reached! giving up"); } } </code></pre> <p>This is just a rough layout of how the input would basically look like. It would probably be encapsulated into a function (in which case you'd want to bail out of from a closed input somewhat differently, possibly using an exception or a special return value). The main part of his is to</p> <ol> <li>restore the stream back to good state using <code>std::isteam::clear()</code></li> <li>skip over the bad input, in this case using <code>std::getline()</code> with a <code>std::string</code>; you could also just <code>std::istream::ignore()</code> the remainder of the line</li> </ol> <p>There may be other problems with your menu but without seeing concrete code I'd think it is hard to tell what the concrete problems are.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload