how to convert a character to an integer in C++?
<p>How to convert a character to an integer in C++??</p>

<p>I want to input integers from user and stop the input as soon as the user enters a *.
I am using the following code:</p>

<pre><code>while(true) {
  cin &gt;&gt; x;
  if (x == (int) '*')
    break;
}
</code></pre>

<p>where I am explicitily typecasting * into an int. But this doesnt seem to work.</p>

<p>I also tried </p>

<pre><code>while(true) {
  cin &gt;&gt; x;
  if (x == (int) '*' - '0')
    break;
}
</code></pre>

<p>But it didn't help much.What else can I do?? 
x indeed is an integer.
But i want to input an integer from the user. Only when the user enters * I want to go out of loop.
Should I declare x as char and then convert it into int and use it?
Cant i convert the char to an int?</p>
