Thread: C++ File I/O Help

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    3

    C++ File I/O Help

    Ok so im working on a project... here are the specs:

    I'm given a data.txt file with the following info:


    0 || person_name || status

    the 0 represents a number between 0-228 (not all the numbers in between)... basically this number is an "Arrival time" (this program is a simulation)..

    The status field is tells what kind of person they are (specificly alumni , etc)

    Basically my question is this... how do I read in data from a outside source? I want to store the numbers into an array, the name into a seperate array, and finally the status in another. (3 arrays)... How do I do that?


    The specific assignment im trying to work on is located here:
    http://www.cs.unt.edu/~roden/courses/3400/homework2.txt
    and the data file is here:
    http://www.cs.unt.edu/~roden/courses/3400/hm2_data.txt


    thank you for your time.

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    3
    Lots of views, yet no posts... Is there no one out there that can help?

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    First off it don't bump your posts. Someone will give you an answer when they have a chance.
    Second you need to read this http://cboard.cprogramming.com/annou...ouncementid=39

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Lots of views, yet no posts... Is there no one out there that can help?
    As one of the views, I feel obliged to defend my choice not to reply. You're problem is both uninteresting and common. That combination is good for being ignored as you can find your answer with a board search. I'm also sure plenty of people will reply to inform you of that.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    3
    im not asking you to do my homework for me... my question is simple (yeah sorry if its not interesting but oh well):


    How do you input data from a text file into an array? ....

  6. #6
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    char *buf = new char[MAX_LEN];

    ifstream data.open("test".txt);
    data.getline(buf);

    data.close()

    delete buf;

    That is very basic, and some of the syntax might be a bit off. But it will give you something to read into.
    Be a leader and not a follower.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >im not asking you to do my homework for me...
    I didn't think you were.

    >yeah sorry if its not interesting but oh well
    That wasn't my point. My point was that if you searched the boards before starting a new thread, you would have found your answer.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-30-2004, 11:21 PM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM