#include #include <fstream> int main() { std::ifstream entree("in.txt"); std::ofstream sortie("out.txt"); std::string ligne; int num_ligne = 0; while (std::getline (entree, ligne)) { ++ num_ligne; sortie << num_ligne << " " << ligne << std::endl; } return 0; }
#include #include <fstream> #include <string> using std::ifstream; using std::ofstream; using std::string; struct Page { string val; Page* suivant; }; // créer une liste de mots à partir d'un fichier texte Page* creerliste() { ifstream entree ("entr.txt"); string i; Page* premier; Page* precedent; Page* nouveau; premier = new Page; entree >> premier->val; precedent = premier; while (entree >> i) { nouveau = new Page; precedent->suivant = nouveau; precedent = nouveau; nouveau->val = i; } precedent->suivant = 0; return premier; } //éliminer les mots qui existent dans la liste du fichier texte et mettre //le résultat dans un autre fichier texte void compare(Page* debut) { int i 0, num_ligne 0; ifstream ifs("in.txt") ; ofstream ofs("out.txt"); string s; Page* head = debut; while (ifs >> s) { debut = head; while (debut != 0) { if (s == debut->val) { i = 1; break; } debut = debut->suivant; } if (i != 1) if( !std::getline(ifs, s)) ofs << s << " "; else { ++ num_ligne ; ofs << num_ligne << " " << s << std::endl; } i = 0; } } int main() { Page* premier = creerliste(); compare(premier); return 0; }