File i/o... integers

This is a discussion on File i/o... integers within the C++ Programming forums, part of the General Programming Boards category; I need to know how to read a number in a text file as an integer, not a string. The ...

  1. #1
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40

    File i/o... integers

    I need to know how to read a number in a text file as an integer, not a string. The number is on its own line which makes it easier I'm sure, but getline() takes a "char" as an argument. I have tried Google and the board search to try and find my answer but haven't. Thanks for any help!
    - Grady (:

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    int MyInt;
    ifstream ReadFile;
    ReadFIle.open(...);
    
    ...
    
    ReadFile >> MyInt;
    
    ...
    
    ReadFile.close();
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40
    Geez, I feel like an idiot... Thanks Magos!
    - Grady (:

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Subtle(?) File I/O Problem
    By cecomp64 in forum C Programming
    Replies: 9
    Last Post: 07-16-2008, 11:39 AM
  2. File I/O Question
    By Achy in forum C Programming
    Replies: 2
    Last Post: 11-17-2005, 11:09 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21