- #include <iostream>
- #include <vector>
- #include <string>
- #include <stdlib.h>
-
- using namespace std;
-
- int Split(vector<string>& vecteur, string chaine, char separateur)
- {
- vecteur.clear();
-
- string::size_type stTemp = chaine.find(separateur);
-
- while(stTemp != string::npos)
- {
- vecteur.push_back(chaine.substr(0, stTemp));
- chaine = chaine.substr(stTemp + 1);
- stTemp = chaine.find(separateur);
- }
-
- vecteur.push_back(chaine);
-
- return vecteur.size();
- }
-
- int main()
- {
- cout << "Test de split\n" << endl;
-
- string str = "Bonjour le monde ...";
- vector<string> VecStr;
-
- int nbTabl = Split(VecStr, str, ' ');
-
- cout << "Nb de parties : " << nbTabl << "\n" << endl;
-
- for(int i = 0; i < nbTabl; ++i)
- {
- cout << i << " : '" << VecStr[i] << "'" << endl;
- }
-
- cout << endl;
-
- system("PAUSE");
-
- return 0;
- }
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;
int Split(vector<string>& vecteur, string chaine, char separateur)
{
vecteur.clear();
string::size_type stTemp = chaine.find(separateur);
while(stTemp != string::npos)
{
vecteur.push_back(chaine.substr(0, stTemp));
chaine = chaine.substr(stTemp + 1);
stTemp = chaine.find(separateur);
}
vecteur.push_back(chaine);
return vecteur.size();
}
int main()
{
cout << "Test de split\n" << endl;
string str = "Bonjour le monde ...";
vector<string> VecStr;
int nbTabl = Split(VecStr, str, ' ');
cout << "Nb de parties : " << nbTabl << "\n" << endl;
for(int i = 0; i < nbTabl; ++i)
{
cout << i << " : '" << VecStr[i] << "'" << endl;
}
cout << endl;
system("PAUSE");
return 0;
}