Computing.Net > Forums > Programming > Searching file w/ C++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Searching file w/ C++

Reply to Message Icon

Name: nucnuc
Date: December 19, 2006 at 06:05:07 Pacific
OS: xp
CPU/Ram: 2gb
Product: dell
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: SmittyZ3M
Date: December 24, 2006 at 12:30:48 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Searching file w/ C++

search file/filetype from last mod? www.computing.net/answers/programming/search-filefiletype-from-last-mod/15993.html

Problem reading file in c++ www.computing.net/answers/programming/problem-reading-file-in-c/7826.html

running .exe file by C# www.computing.net/answers/programming/running-exe-file-by-c/12335.html