Click here to Skip to main content
16,013,918 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the below program i have a file aa.txt which is having the numbers written in the form of 01234 and i am reading this file character by character using get() , but i want to put all the numbers in the integer form in temp but it is not able to convert as 01234 , it is assigning as 48 49 50 51 52 . How can i convert them from character to integer?

What I have tried:

int main()
{
    ifstream f;

    int sum=0;
    int temp[5];
    f.open("E://aa.txt",ios::in);

    char c;
    int num[5];
    char num2[5];
    int j=0;
    while(!f.eof())
    {
        c=f.get();
        cout<<c<<" ";
        num[j]=c;
        j++;
    }


    for(int i=0;i<5;i++)
    {
        num2[i]=num[i];
        temp[i]=(int)num2[i];
        cout<<temp[i]<<" ";
    }
}
Posted
Updated 29-Nov-18 0:08am
Comments
Afzaal Ahmad Zeeshan 29-Nov-18 6:47am    
Parsing a character to integer only requires you to change its notation in ASCII from character, to the number values.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900