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!

Simple file IO

Status
Not open for further replies.

MinnisotaFreezing

Programmer
Jun 21, 2001
120
KR
Sorry if this is an easy question, I searched Google and Tek-Tips, and cant find what I want.

I have a .txt file with 100 words seperated by a delimiter. I want to read just the nth word.

What I can do is read in a line, or the file, then use strtok or CString.Find and find the 15th and 16th comma, then read the word in the middle, and trim the white space. What I want to do is just get that 15th word, or 67th word, or whatever. I can probably use peek to check, but its been a while.

The $1000 doller question is, does it matter? If I want the 15th word, I suppose I have to access all the data before the 15th word to find the 15th word anyway. Does it matter if I do it using file I/O, or is it just as efficent to read the whole file into a buffer, and then parse my data that way.

Best world would be to use MySql or Access, but that is not possible. Barring that, is there anything more efficent that a simple delimited text file?

Thanks for your help.
 
You can use getline and use the delimeter character n times. Then the nth time you will have what you are looking for. Just a very basic solution. Could be something better.

-Skatanic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top