Thread: C++ file access

  1. #1
    Registered User
    Join Date
    May 2002

    Question C++ file access

    I have a text file, either created manually, or as an output from a vb program (not yet completed, so output format can be modified slightly), that I need to input into my c++ program. I need to be able to read a series of integers, characters and floats from the file, in order and assign these values to the correct type of variable.
    Currently, I can only open the file and read in the character values bit by bit or in blocks. Does anyone know how I can get this to work?

  2. #2
    Registered User
    Join Date
    Dec 2001
    ifstream will open a file for reading, as tho it were coming from cin

    ifstream input("filename.txt");
    int anInt;
    char aChar;
    double aDouble;
    float aFloat;

    if ( )
    cout << "Error unable to open filename.txt";
    return -1;
    input >> anInt >> aChar >> aDouble >> aFloat;

    That would read an int, a char, a double, then a float from the file "filename.txt"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM