Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- bool test_accent(string mot) {//test si il y a des accents dans le mot
- for (int i = 0; i<mot.size(); i++)
- if (mot.at(i) < 'a' || mot.at(i) > 'z') return true;
- return false;
- }
- int EcrireFichierMots(string nomDuFichier, vector<string>& motsDisponibles) {//Ecrit le vecteur dans le fichier
- ofstream Dictionnaire(nomDuFichier);
- if (Dictionnaire)
- {
- for (int i = 0; i < motsDisponibles.size();i++)
- Dictionnaire<<motsDisponibles[i]<<endl;
- return 1;
- }
- else return -1;
- }
- int lireFichierMots_sans_accent(string nomDuFichier, vector<string>& motsDisponibles)//stock touts les mots sans accent dans un vecteur
- {
- //ouverture d'un flux de lecture
- ifstream Dictionnaire(nomDuFichier);
- string mot;
- int nb_mots = 0;
- if (Dictionnaire)
- {
- //lecture des lignes et implémentation dans le vecteur et dans le nombre de mots qu'il contient
- while (getline(Dictionnaire, mot)) {
- if (test_accent(mot) == false) {//test accents
- motsDisponibles.push_back(mot);
- nb_mots++;
- }
- }
- return nb_mots;
- }
- else return -1;
- }
- int main() {
- string nomDuFichier = "C:/dico.txt";//emplacement du dictionnaire
- string nomDuFichier_sans_accent = "C:/dico_sans_accent.txt";//emplacement du dictionnaire sans accents
- vector<string> Dictionnaire;
- int taille_vecteur = lireFichierMots_sans_accent(nomDuFichier, Dictionnaire);
- if (taille_vecteur == -1)
- {
- cout << "Impossible d'ouvrir le fichier dico.txt" << endl;
- return -1;
- }
- if (EcrireFichierMots(nomDuFichier_sans_accent,Dictionnaire) == -1)
- {
- cout << "Impossible d'ouvrir le fichier dico_sans_accent.txt" << endl;
- return -1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment