-1

Using type casting to convert string into integer

string str="123456";
int buffer[str.length()];
for (int i=0; i<str.length();i++)
{
    buffer[i]=(int)str[i];
    cout << buffer[i];
}

Getting following result 495051525354 which is DEC form of Symbol 123456

But i want "123456" as a result. Please help!!

1 Answers1

-1

Got workaround by my self

string str="123456";
int buffer[str.length()];
for (int i=0; i<str.length();i++)
{
buffer[i]=(int)str[i] - 48;
cout << buffer[i];
}