1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #include <vector>
#include <string>
using namespace std;
vector<string> split(const string &str, const string &separator)
{
vector<string> strVect; // pour la valeur retour
if (str.empty())
return strVect; // vecteur vide
int pos = 0;
size_t size;
do
{
size = str.find(separator, pos);
if (size != string::npos)
{
strVect.push_back(str.substr(pos, size - pos));
pos = size+1;
}
else
strVect.push_back(str.substr(pos, str.size()));
} while (size != string::npos);
return strVect;
} |