Hello, today i come to you all in need of guidence! I've googled and seen some stuff but it all kinda confuses me as it's a bit of a jump from where i left off in c++ but is there a guide or anything out there explaining a SEARCH function i don't think im advanced enough to try to connect a DB with info to a program so instead i want to do it from the program itself so my goals
1. Get this working
2. Maybe try to make it a actual program not console application?
3. Have a search function where if you type search (X Y Z) or in a search bar put (X Y Z) it will bring up something in the code that matches EG
Search term: Hammers
brings up
Ballpoint Hammer
Reindhardt Hammer
Other Names of Hammers
None currently as it all kinda revolves around this search function
Any help is greatly appreciated as i am yet to find a good guide explaining simply how searching works in c++
Another thing i ponder:
The ability to add to a program like this?
So they can do something in the program that will somehow add info they input so eg:
add new hammer1 so next time they search for hammers they will also see new hammer 1
I thought of putting it all in a text file and the program just searches through the text file and outputs it or adds it to the text file but i figured there's a better way
#include <iostream>
#include <string>
int main()
{
std::string sRef = "Hammers";
std::string sSearch1 = "Ballpoint Hammer";
for (size_t length = 0; length <=1; ++length)//searching the entire string & a substring one size short
{
std::size_t found = sSearch1.find(sRef.substr(0, sRef.size()-length));
//check whether string being searched has the substring of the reference string
if (found!=std::string::npos)
{
std::cout << "Found " << sRef.substr(0, sRef.size()-length) << " within " << sSearch1 << '\n';
}
else
{
std::cout << "No match for " << sRef.substr(0, sRef.size()-length)<< '\n';
}
}
}
Output
1 2
No match for Hammers
Found Hammer within Ballpoint Hammer
Few points:
1. you can determine at what point to stop searching the reference string by varying the boundary condition for length
2. currently the search is case sensitive, you can make it case insensitive by converting both strings to lower or upper case throughout first and then searching
3. if you consider proceeding with this approach your next steps might be: (a) putting the code into a function, (b) testing it against a std::vector<std::string>, (c) searching files, (d) building a stand-alone program out of it
This is already my idea @gunnerfunner i want to have like a text box on a GUI application they enter the search term and then click search and then it will query a databse to try to find it so in an example something like the hammers or a customer database so you click search on the application and then it searches the database for all customers named Alex and outputs their first name last name and some other notes in the DB
OR if i can have it built into the application somewhere, i'd just rather not have a text file have to follow around the .exe for it to work and since i am already trying to figure out a way to do a login if i learn how to incorporate DB into C++ then kinda two birds one stone