1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <fstream>
#include <iostream>
#include <string>
#include <cstring>
#include <limits>
#include <cstdlib>
int main()
{
std::string name, lang, line;
bool is_lang = false;
//A_LISTER LES FICHES
std::cout << "Здравствуйте !" << std::endl;
std::cout << "FICHIERS DISPONIBLES EN LECTURE:" << '\n' << '\n' << std::endl;
system( "dir c:\temp /A /B /O:GEN" );
//B_SAISIR NOM DE FICHE
std::cout << '\n' << "Entrer le nom de fichier:" << std::endl;
std::getline( std::cin, name );
//C_SAISIR LA LANGUE D'AFFICHAGE
std::cout << '\n' << "Choix de la langue: [FR|RU]" << '\n' << std::endl;
std::getline( std::cin, lang );
//D_AFFICHER LES MOTS DE LA PARTIE "LANGUE" A "FIN_LANGUE"
// le constructeur de ifstream permet d'ouvrir un fichier en lecture
std::ifstream File( name.c_str() ); //nécessité de convertir le string en char
if ( File ) // ce test échoue si le fichier n'est pas ouvert
{
// cette boucle s'arrête dès qu'une erreur de lecture survient ou qu'on arrive à la fin de la section
while ( std::getline( File, line ) && line != "END_"+lang)
{
if(is_lang)
{
// afficher la ligne à l'écran
std::cout << line;
}
if(line == lang) {is_lang=true;}
}
//pause:
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
//nettoyage du buffer et rembobinage au début
File.clear();
File.seekg(0, std::ios::beg);
//E_A CHAQUE FOIS QU'ON APPUIE SUR ENTREE, AFFICHER LA REPONSE
std::cout << '\n' << "Appuyer sur entrée pour afficher la correction" << '\n' << std::endl;
if(lang == "RU")
{
lang = "FR";
}
else
{
lang = "RU";
}
while ( std::getline( File, line ) && line != "END_"+lang)
{
if(is_lang)
{
// afficher la ligne à l'écran
std::cout << line;
//pause:
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
}
if(line == lang) {is_lang=true;}
}
File.clear();
File.seekg(0, std::ios::beg);
}
//F_APPUYER SUR X TOUCHE POUR REVENIR AU MENU
std::cout << '\n' << "Appuyer sur entrée pour revenir au menu" << std::endl;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
return 0;
} |
Partager