Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new to Visual C++ File Handling

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
Hello,

I am trying to write a program that reads a csv file and parses it. I don't know the best way to do this.

I can use fstream (I am most familiar with this), CFile, or the built in serialize stuff. Which offers the most flexability for what I want to do?

There seems to be so many ways of file handling with this visual C++ that I seem a bit lost.

Thanks
 
The built in serialize stuff is easy to use. It's very similar to fstream, but you don't have to worry about opening the file or anything - MFC does that for you. All you have to worry about is what variables to write to and read from the file. Serializing even works with CStrings, which fstream doesn't do, so I would definately use serializing.
 
Use fstream for file and strtok() to parse each line.
You can use also CStdioFile and CString to read the csv file. To parse, use strtok() or CString::Find() combined with CString::Right() and CString::Mid() to parse a record.
The flexibility for which you are looking is not in the fstream or CFile or CStdioFile but in the parsing method.
-obislavu-


 
Hmm

I think I would like to use fstream because I am more familiar with it but I didn't know that it won't work with CString.

I suppose I could always use the format fuction in CString...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top