-
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?
-
I would start with:
http://www.cprogramming.com/tutorial.html
I believe lesson 10 is what you want.
-
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.
-
Does C++ support SQL? If so, a query would be your answer, something like
PHP Code:
SELECT MAX(Date) FROM 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.
-
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.