C++ reading from stdin using istringstream
<p>Im trying to call different functions from keyboard but I've faced a few problems due to my lack of knowledge/experience with cin,istringstream etc.Here is my simplified code : </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;sstream&gt;

using namespace std;

int main(int argc,char **argv) {

    string line;
    do {
        getline(cin,line);
        istringstream iss(line);
        string word;
        iss &gt;&gt; word;
        if (word ==  "function") {
            int id;
            if (!(iss &gt;&gt; id)) {
                cout &lt;&lt; "Not integer.Try again" &lt;&lt; endl;
                continue;
            }
            cout &lt;&lt; id &lt;&lt; endl;
            iss &gt;&gt; word;
            cout &lt;&lt; word &lt;&lt; endl;
        }
        else cout &lt;&lt; "No such function found.Try again!" &lt;&lt; endl;
    } while (!cin.eof());

    cout &lt;&lt; "Program Terminated" &lt;&lt; endl;
    return 0;
}
</code></pre>

<p>The 2 problems I currently deal with are :</p>

<p><em>• Why after checking if I got an integer the do-while loop terminates when I type something that's not integer? (eg "function dw25")</em>-Had to use continue; instead of break;.Thought break would exit the outer if-condition.</p>

<p>• How can I solve the problem that occurs when I type "function 25dwa" because I don't want to get id == 25 &amp; word == dwa.</p>