Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am writting a program to search a file for certain text. Specifically, I am searching for file names of a specific type that are listed in a text file in no particular order. That is, this file is not in any particular order, delimited by commas or anything like that and will always vary.
My objective is to write a program that will scan this file, find the filename.ext I am looking for and place it in another file in a structured list.
The way I was thinking about doing it was using getline() and searching for a substring (probably the file extension) then some how grabbing the 8 chars before the extension. I'm not sure I am on the right track here, my c++ is a bit rusty to say the least.
Anyway, if someone could put me on the right track, I'd definatly appreciate it. Thanks in advance.

Assuming that the filename and the extension will always be a concatenated string, then this task is quite easy. For example, if the item you are searching for is always going to be theFile.txt then you will not have any issues. if anything is going to be attached to the beginning or ending of the file, or if there are any spaces, this method will not work.
For example:
!@#$theFile.txt#@$
OR
th e F ile. tx t
will not work.
Psuedocode:
ifstream in;
in.open(<filePath>);
while !(in.eof()) // loop through until EOF
{
string temp;in >> temp;
if (temp == "theFile.txt")
{
cout << "it was found" << endl;
// take appropriate action here
}} // while

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |