File I/O specifics

This is a discussion on File I/O specifics within the C++ Programming forums, part of the General Programming Boards category; Can anyone tell me all about file i/o with fstream?I used to know this but forgot.I need to know particulars,for ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    44

    File I/O specifics

    Can anyone tell me all about file i/o with fstream?I used to know this but forgot.I need to know particulars,for example and especialy:
    how would you write at the end of an already eisting file.Also how would you read a date out of a string,e.x.:

    Database accessed at 5:51p 5/15/88 by John smith
    Database accessed at 3:00p 6/12/88 by John smith
    Database accessed at 7:00p 6/13/88 by Jane Shelton
    Database accessed at 2:15p 6/14/88 by John smith
    .
    .
    .
    .
    .
    Database accessed at 5:20p 8/18/02 by Marcy Peyng
    Database accessed at 12:00p 8/19/02 by Jennifer Lane
    Database accessed at 1:00p 8/28/02 by John smith

    now how would you read the date that the Database was LAST accessed BY Jennifer Lane?
    ego sum via et veritas et vitae -Jesus Christ

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I would start with:
    http://www.cprogramming.com/tutorial.html

    I believe lesson 10 is what you want.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    44
    yes,I've read that,but im not sure how to use ios append,does it just simply write what you tell it to at the end of the file?And I still need to know how to read as I explained.
    ego sum via et veritas et vitae -Jesus Christ

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    Does C++ support SQL? If so, a query would be your answer, something like
    PHP Code:
    SELECT MAX(DateFROM MyDB WHERE name 'Jennifer Lane' 
    I know it can be done in VB, hard to believe can't be done in C++, although never actually seen it.
    Truth is a malleable commodity - Dick Cheney

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    there are a variety of ios:: flags that can be used with ostreams. They are most often indicated in the declaration of the stream. If not declared otherwise the ios::trunc flag is the default. To append to the end of a file named data.txt which is located in the same subdirectory as the exe. of the program you are using you can do something like this:

    ofstream fout(ios::app);
    fout.open("data.txt");

    To extract the data fields from the entire line you need to parse the line. The process to do this depends somewhat on whether the data is stored in a reproduceable or a random format. The example provided seems regular. Therefore you could call the >> operator three times and ignore the input. Then call the >> a fourth time to extract the 5:51p from the example below. Using the >> operator a fifth time will extract the 5/15/88 from below. Calling >> three more times will get you to the next line where you can do it all over again.

    Database accessed at 5:51p 5/15/88 by John smith

    once you have isolated the given fields you can further parse them into month, day, year, convert to military time or whatever you want to do with them.

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, 08:35 AM
  2. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 03:47 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. File I/O problem
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 12
    Last Post: 09-03-2005, 12:14 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 04:56 AM

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