Steefmaester

Suppression des accents

Nov 11th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. bool test_accent(string mot) {//test si il y a des accents dans le mot
  9.  
  10.     for (int i = 0; i<mot.size(); i++)
  11.         if (mot.at(i) < 'a' || mot.at(i) > 'z') return true;
  12.     return false;
  13.  
  14. }
  15.  
  16.  
  17. int EcrireFichierMots(string nomDuFichier, vector<string>& motsDisponibles) {//Ecrit le vecteur dans le fichier
  18.    
  19.     ofstream Dictionnaire(nomDuFichier);
  20.     if (Dictionnaire)
  21.     {
  22.         for (int i = 0; i < motsDisponibles.size();i++)
  23.         Dictionnaire<<motsDisponibles[i]<<endl;
  24.         return 1;
  25.     }
  26.  
  27.     else  return -1;
  28.  
  29. }
  30.  
  31.  
  32.  
  33. int lireFichierMots_sans_accent(string nomDuFichier, vector<string>& motsDisponibles)//stock touts les mots sans accent dans un vecteur
  34. {
  35.     //ouverture d'un flux de lecture
  36.     ifstream Dictionnaire(nomDuFichier);
  37.     string mot;
  38.     int nb_mots = 0;
  39.     if (Dictionnaire)
  40.     {
  41.         //lecture des lignes et implémentation dans le vecteur et dans le nombre de mots qu'il contient
  42.         while (getline(Dictionnaire, mot)) {
  43.             if (test_accent(mot) == false) {//test accents
  44.                 motsDisponibles.push_back(mot);
  45.                 nb_mots++;
  46.             }
  47.         }
  48.         return nb_mots;
  49.     }
  50.     else return -1;
  51.  
  52.  
  53. }
  54.  
  55. int main() {
  56.  
  57.     string nomDuFichier = "C:/dico.txt";//emplacement du dictionnaire
  58.     string nomDuFichier_sans_accent = "C:/dico_sans_accent.txt";//emplacement du dictionnaire sans accents
  59.     vector<string> Dictionnaire;
  60.     int taille_vecteur = lireFichierMots_sans_accent(nomDuFichier, Dictionnaire);
  61.     if (taille_vecteur == -1)
  62.     {
  63.         cout << "Impossible d'ouvrir le fichier dico.txt" << endl;
  64.         return -1;
  65.     }
  66.  
  67.     if (EcrireFichierMots(nomDuFichier_sans_accent,Dictionnaire) == -1)
  68.     {
  69.         cout << "Impossible d'ouvrir le fichier dico_sans_accent.txt" << endl;
  70.         return -1;
  71.     }
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment