سلام.به نظرم اگر از c++11 استفاده می کنید بهینه ترین روش استفاده از regex هستش .
#include <iostream>
#include <string>
#include <regex>
int main ()
{
std::string s ("My IP is ... 127.0.0.1\n");
std::smatch m;
std::regex e ("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
while (std::regex_search (s,m,e)) {
for (auto x:m) std::cout << x << " ";
std::cout << std::endl;
s = m.suffix().str();
}
return 0;
}