add split string to vector int

This commit is contained in:
chatlanin
2022-08-15 21:02:19 +03:00
parent aa468cc3d2
commit cb55987746
3 changed files with 30 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
namespace hack::string
{
using v_str = std::vector<std::string>;
using v_int_str = std::vector<int>;
template<typename T>
v_str split_str(const std::string& str, T t)
@@ -25,6 +26,26 @@ namespace hack::string
end = str.find_first_of(t, begin);
}
v.emplace_back(str.substr(begin));
return v;
}
template<typename T>
v_int_str split_stoi(const std::string& str, T t)
{
v_int_str v;
std::string::size_type begin = 0;
std::string::size_type end = str.find_first_of(t);
while(end != std::string::npos)
{
v.emplace_back(std::stoi(str.substr(begin, end - begin)));
begin = ++end;
end = str.find_first_of(t, begin);
}
v.emplace_back(std::stoi(str.substr(begin)));
return v;
}
}