The program consists only of entering a name, and if it is in the file, display a menu. Otherwise the menu is not displayed and the program is terminated by the function fin () that returns in 0.
However, even if the name is not found in the file, the menu is displayed.
#include <iostream>
#include <string>
#include<fstream>
using namespace std;
bool localizacionJugador(char apodo);
void menu();
int fin();
int main()
{
ofstream ficheroSalida;
ficheroSalida.open("db2.txt");
ficheroSalida << "a";
ficheroSalida.close();
char apodo;
cout << "Introduzca su nombre:";
cin >> apodo;
localizacionJugador(apodo);
menu();
}
bool localizacionJugador(char apodo)
{
char c;
bool encontrado=false;
fstream ficheroEntrada;
ficheroEntrada.open("db2.txt");
if(ficheroEntrada.is_open())
{
while(!ficheroEntrada.eof() && c!=apodo)
{
ficheroEntrada.get(c);
}
encontrado=c==apodo;
if(encontrado==true)
{
cout << "Usuario encontrado"<<endl<<endl;
}else
{
cout << "Usuario no encontrado";
fin();
}
}else
{
cout << "Fichero no encontrado";
fin();
}
ficheroEntrada.close();
return encontrado;
}
void menu()
{
cout << "Este es el menu";
}
int fin()
{
return 0;
}