سلام
بهترین و حرفه ای ترین راه استفاده از Regular expression هستش برای مثال قطعه کد زیر را میزارم.
https://docs.microsoft.com/en-us/cpp/standard-library/regex-functions?view=vs-2019
string Mytext = "add string hju and number 1379";
regex re(R"(\d+)"); //====>>> از یک تا بی نهایت عدد پشت سر هم
/// آیا عبارت مورد جستجو در رشته است اگر وجود دارد استخراج شود
std::smatch sm;
if (regex_search(Mytext, sm, re))
{
for (size_t i = 0; i < sm.size(); i++)
{
cout << sm.str(i)<<endl;
cout << "-------" << endl;
}
}
/// عبارت مورد نظر در کل رشته جستجو شده و یک آرایه از ان برگشت داده میشود
re = R"(\w+)"; //=====>>> کلمات استخراج میشود
std::sregex_iterator next(Mytext.begin(), Mytext.end(), re);
std::sregex_iterator end;
while (next != end) {
std::smatch match = *next;
std::cout << match.str() << "\n";
next++;
}