how can i convert from char to int? I keep getting errors, or the conversion changes the number.
etc.
char cVar = '1';
int nVar = (int)cvar;
now...
int == 6532465
why???
how can i convert from char to int? I keep getting errors, or the conversion changes the number.
etc.
char cVar = '1';
int nVar = (int)cvar;
now...
int == 6532465
why???
A char is one byte. This means it can hold a maximum value of 2^8 or 128 if signed, 256 if unsigned.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
what you are doing will put the ascii val of cVar into nVar
use atoi() in stdlib.h for converting the numerical value in char into an integer.
Code:char *c="12345"; int i; i=atoi(c); cout<<"I is : "<<i;
-
Since you are using char to describe it, I would assume you want '0'..'9' in int form, then a simple thing is:
For a string that represents a number, example above is good.Code:char c = '2'; int ic = (int)(c - '0');