Results 1 to 3 of 3

Thread: char to int

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    54
    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;
    }
    Last edited by Flamer; Mar 7th, 2001 at 12:11 PM.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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:
    Code:
    int x = atoi("56");
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151

    Question

    Code:
    #include <iostream.h>
    
    
    void main()
    {
    	char c;	
    
    	c = 'A';
    	cout << (int)c << endl;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width