Ok, I am def a beginner in writing code (use to be ok, but haven't done it in soooo long, so I am very rusty). Let me give a little background about the program I am trying to write before I get to my question so that it makes a little more sense. I work in a jewelry store for my uncle, and I am trying to write a program that will help us search our repair jobs. As of now, to organize everything, I make each customer a folder named as their name (ie Mike Smith). Inside their personal folder I save a notepad file named their name (ie Mike_Smith.txt). In that text file, I include information such as the job #, telephone #, description of the pieces, charges, take in date, ready date, and location of the repair job. It has been working really well, except for the fact that we have to know the customers first name to be able to find any information. An example of how this is a problem is a repair needed a piece of jade replaced, but we could not remember who the customer was. With having at least 3,000 customers, and a few hundred repair envelopes at a time, you can see how this is so difficult to keep track of. I have the code written for the cout statements, as well as the cin. What I need it to do is if I type in a keyword such as Jade, the customers name, or job number, it will open that .txt file, that I have already created for the customer. I have been searching everywhere for the right direction to take with this, a starting point, or even an example but I come up empty handed. If anyone can help me with this, I wouldn't be able to thank you enough. So far with the folders I have cut the search time from a few hours, to like 15-30 mins which is HUGE, but if I can finish this program, I believe the search will be cut to instant, which will make my life SOOOO much easier! Thank you in advance to anyone that may be able to help!

WaltP commented: Use paragraphs please. Not even going to read a blob of text this big -4

The MS Windows search function would let you find things in text files quickly like that.

Other than that, what compiler are you using?
It would be easier done in C++/CLI if at all possible.

The MS Windows search function would let you find things in text files quickly like that -- assuming you're using Windows.
Also, since you mentioned "cout", another assumption is that you're doing this from the command-line.

Other than that, what compiler are you using?
It would be easier done in C++/CLI if at all possible.

Do the text files have any structure to them?
...or is this just a random text search inside a text file?

** If this is homework, don't bother reading below this line **

Also, I would seriously recommend converting all of this to a database.
That way, you can avoid cofusing the Sapphire Johnson Ruby repair with the Ruby Jones Sapphire repair job.
Also, keeping it in a database would make it easier at tax time.

In a file-based system, each new order makes the system slower as the files probably need to be searched sequentially.

With 3000 customers, there must be some similar or duplicate names.
You mentioned nothing of an order number.

If you want a strictly c++ approach, you could create a master .txt file of all the file paths for all your files. This will allow you to load and search through all ye' existing files.

////master.txt
//a list of all your existing text files
aaron_rogers.txt
brett_favre.txt
calvin_johnson.txt
jahvid_best.txt
mathew_stafford.txt
tom_brady.txt
tony_romo.txt

Now you can do a little somthin' like this:

//will return the names o' the files that contain your keyword
string keyword_search(string& target, ifstream& master)
{     
     ifstream customer;
     string file_path;

     getline(master, file_path);
    
     customer.open(file_path.c_str());

     if(!customer.is_open())
     {
          cout << "\aError! " << file_path << " could not be opened. ";
          cout << "\nFile may have been moved, renamed, or deleted. ";
          cout << "\nPress [ENTER] to continue... ";
          cin.get();
     }
  
     while(customer)
     {               
          if(file_path.find(target.c_str());
          {
               customer.close();
               return file_path;
          }
     }

     customer.close();
     return;
}

call this funtion in a loop and store all the results in a string array.

ran out of edit time.

If you want a strictly c++ approach, you could create a master .txt file of all the file paths for all your files. This will allow you to load and search through all ye' existing files.

////master.txt
//a list of all your existing text files
aaron_rogers.txt
brett_favre.txt
calvin_johnson.txt
jahvid_best.txt
mathew_stafford.txt
tom_brady.txt
tony_romo.txt

Now you can do a little somthin' like this:

//will return the names o' the files that contain your keyword
string keyword_search(string& target, ifstream& master)
{     
     ifstream customer;
     string file_path;
     string cust_info;
     string not_found("not found");

     getline(master, file_path);
         
     customer.open(file_path.c_str());

     if(!customer.is_open())
     {
          cout << "\aError! " << file_path << " could not be opened. ";
          cout << "\nFile may have been moved, renamed, or deleted. ";
          cout << "\nPress [ENTER] to continue... ";
          cin.get();
          return not_found;
     }
  
     while(getline(customer, cust_info));
     {               
          if(cust_info.find(target.c_str());
          {
               customer.close();
               return file_path;
          }
     }

     customer.close();
     return not_found;
}

call this funtion in a loop and store all the results in a string array.

Wow, this is awesome! Thank you so much!! I'm sure this will def help me out! P.S. I loooovee how you used NFL player names! AWESOME!

I'm using an ANCIENT compiler. Turbo C++. Any suggestions for a really good FREE compiler I should get?

try codeblocks or bloodshed dev c++.

Visual C++ Express Edition.

Create two index files, perhaps?

keywords.idx for keywords with each line containing: keyword path, [ path... ]
jade aaron_rogers.txt brett_favre.txt calvin_johnson.txt
amethyst jahvid_best.txt mathew_stafford.txt
urgent tom_brady.txt tony_romo.txt
// etc

ordernumbers.idx with each line containing: ordernumber path
10237 aaron_rogers.txt
11384 brett_favre.txt
etc.

On program startup read keywords.idx into a std::map< std::string, std::vector<std::string> >, update it as entries are being made and on shutdown write it back to keywords.idx.

Likewise for ordernumbers.idx with a std::map< std::string, std::string >

commented: very nice STL implementation +10
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.