2
I want to do a text search, like the ones I do in Mysql. Ex: LIKE "9%4"
I tried to implement a find_if()
, but without success.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int n;
string a;
cin >> n;
while(n--)
{
cin >> a;
if(a.find("35") != string::npos)
cout << "-" << endl;
else if(a.find("190") != string::npos)
cout << "?" << endl;
else if(find_if(a.begin(), a.end(), "9*4") != a.end())
cout << "*" << endl;
else
cout << "+" << endl;
}
return 0;
}
I can go all the way string manually and search for "9*4"could be any number, but I believe there must be a smarter way to do that.
Thanks for the answer, in the first code you posted, if the entry was 94 it would enter in it too, wouldn’t it? I forgot to mention also that there will only be one number between 9 and 4.
– Emanuel Huber
I answered what was asked. If you can only have one character is quite different from what is in the question. Then it is simple, just see if the size of the string is 3 too.
– Maniero