// cString.cpp Utilisations de la classe string
// > Initialiser un tableau de string, l'afficher; ajouter un élément
// > Convertir un objet 'string' en majuscule
// > Trouver la chaîne la plus longue dans le tableau
// > Chercher les éléments contenant une sous-cahîne
// > Isoler l'extension dans un nom de fichier
// > Supprimer espaces en tête et en queue: fonction suppEspaces()
//
// auteur: R.Astier
//----------------------------------------------------------------------
//
#include
#include
using namespace std;
//----------------------------------------------------------------------
// Supprimer espaces tabulations ... en début et fin de chaîne
// par défaut pas de suppression à la fin
void suppEspaces(string & ch, int suppEnFin=0) {
unsigned int ind = ch.find_first_not_of(" \t\n\r\b");
// Suppression au début
ch.erase(0,ind);
if(ind == string::npos || !suppEnFin) return;
// Suppression à la fin
ind = ch.find_last_not_of(" \t\n\r\b");
ch.erase(ind+1,string::npos);
}
//-------------- Q u e l q u e s u t i l i s a t i o n s ----------
int main( int ntm, char *tm[]) {
const int MAXSP=6;
// Initialiser un tableau de string
string sp[MAXSP]={"FootBall","VoleyBall","Surf"};
unsigned int nsp=3; // nb cases utilisées dans sp
unsigned int i;
// Affichage du tableau
cout <<"Les sports ==> ";
for(i=0; i ";
unsigned int pos;
for( i=0; i ";
if(pp == string::npos) ext="";
else ext=nf.substr(pp+1); // on enlève le .
cout<<"'"< ";
if(pp == string::npos) ext="";
else ext=nf.substr(pp+1); // on enlève le .
cout<<"'"< '/usr/src' chaine.cpp
// chaine.cpp ==> '.' chaine.cpp
// /chaine.cpp ==> '' chaine.cpp
// Conversion string ==> tableau de caractères
// tab.caractères ==> numérique strtol
// numérique ==> string
// Lire une chaîne
//
cout<<"\n> > > "; cin.getline( new char[80],80);
return 0;
}
//fin cString.cpp