I don't know what to do. Here is my code;
Code:
void findMatch(){
string temp1;
string temp2;
vector<string> text_file1;
std::ifstream hfin1("holdSentence.txt", fstream::app), fin2("holdDatabase.txt", fstream::app);
if (!hfin1 || !fin2) { std::cerr<<"file error\n"; std::exit(1); }
getline( hfin1, temp1 );
while( getline( fin2, temp2 ) ){
for (string::size_type a = 0; a < temp2.length(); ++a) {
if(temp2[a] == '4' ){
for (string::size_type b = 0; b < temp1.length(); ++b) {
if(temp1[b] == '1' ){
cout << endl << temp2 << " " << temp1 << endl;
}
}
}
}
text_file1.push_back( temp2 );
}
hfin1.close();
fin2.close();
}
And here is my program output;
Code:
Enter your sentence, end it with a period: apple.
Input sentence to program, from input.txt;
appplle
xxxyy 4 appplle 1 // This is from the function
yyyzz 4 appplle 1 // This is from the function
zzzaa 4 appplle 1 // This is from the function
Press any key to continue . . .
See this result "zzzaa 4 appplle 1", I want the function to display "zzzaa 4" only, because the two strings "zzzaa " and " appplle " share a char. I have tried many different things for a few days now and I think I have to use substr, but for the life of me I don't know how to use substr in my function to get the result I want.