PDA

Click to See Complete Forum and Search --> : char to int


Flamer
Mar 7th, 2001, 10:50 AM
i'm doin an ifstream .get() to pull in characters from a text file.
and the last character it pulls out a number. I want to return an int value.

Heres the code maybe i'm doing something wrong..

int get_version_num()
{
ifstream din;
do
{
din.get(ltr);
cout<< ltr;
if(ltr=='V')
qans++;
if(ltr=='R')
qans++;
if(ltr=='M')
qans++;
}
while(qans<4);

do
{
din.get(ltr);
i++;
}
while(i<5);

answ = ltr;
return ltr;
}

parksie
Mar 7th, 2001, 12:04 PM
I can't see what you're going at with that code...what's the file it's reading from? Just a few lines is enough. But to convert a string to a number just use atoi:

int x = atoi("56");

KingDavid
Mar 7th, 2001, 01:29 PM
#include <iostream.h>


void main()
{
char c;

c = 'A';
cout << (int)c << endl;
}