input/output files question

This is a discussion on input/output files question within the C++ Programming forums, part of the General Programming Boards category; in C++.net for school our last program program 7 he gave us a sequential file. so im trying to figure ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    input/output files question

    in C++.net for school our last program program 7 he gave us a sequential file.

    so im trying to figure out in all of this how do i print a piece of data(could be string,double,int whatever) from the file out on the screen or at least see if im heading the right direction or not?

    Code:
    IO::StreamReader *infile;
    IO::StreamWriter *outfile;
    infile = IO::File::OpenText("prgv-7.dat");
    infile->ReadLine( );
    outfile->WriteLine("YAY IM WRITING TO A FILE");
    infile->Close( );
    i suppose the part that REALLY gets me is how do i tell what is what when reading a file like how do i tell this is a number or a String. cause what i wrote up there should read from the file right? and the i could write to the file with writeline that part makes sense but having a hard time grasping telling the difference between the data types then putting them on screen for display?

    (will try and catch teacher at office tommorrow but would be good if i wasnt as lost as i am now. it seemed to make sense in class but went braindead at home) lol
    hooch

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    It's up to the reader to decide what to do with what you read. If you read the value 0x41 you could either treat it as the character 'A' or as the decimal value 65 which could be an age, a distance or the number of collected items in a game savefile.
    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
    Join Date
    Nov 2001
    Posts
    255
    so i pretty much determine if its a string/int or whatever and i read it out of the file?

    i just looked at the .dat file again and noticed the 6 pieces of data are written in the same order over and over so essentially all i need to do is read it 6 times in 6 different array string variables? though i think he wants us to use different variable types. cause at the end i have to say which cost the most.

    and print it out that way? i assume thatd work?
    hooch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about reading from files
    By green11420 in forum C++ Programming
    Replies: 12
    Last Post: 04-22-2008, 11:02 AM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  3. a question files
    By amin1982 in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2005, 06:10 AM
  4. Question about ".o" files
    By Jez_Master in forum C++ Programming
    Replies: 1
    Last Post: 04-11-2002, 01:54 AM
  5. input/output + Object Files ?
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2001, 08:32 AM

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