funciones getch y clear

This commit is contained in:
2026-03-14 17:25:51 +01:00
parent ef47cdc25f
commit 31a90187a6

View File

@@ -1,16 +1,44 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <conio> #include <termios.h>
#include <stdio.h>
#include <unistd.h>
using namespace std; using namespace std;
char getch(void){
struct termios oldt, newt;
char ch;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
void clear(){
ifstream archivo("/etc/os-release");
if (archivo.good()) {
system("clear");
} else {
system("cls");
}
};
int main() int main()
{ {
char opcion; char opcion=0;
while (opcion!=8) while (opcion!='8')
{ {
cout<<opcion<<enl<<endl;
cout<<"SANCIONES APP. MENU PRINCIPAL"<<endl; cout<<"SANCIONES APP. MENU PRINCIPAL"<<endl;
cout<<"===================================="<<endl; cout<<"===================================="<<endl;
cout<<"Indroduce un numero entre 1 y 8"<<endl;
cout<<" 1. Consultar cehiculo."<<endl; cout<<" 1. Consultar cehiculo."<<endl;
cout<<" 2. Añadir vehiculo."<<endl; cout<<" 2. Añadir vehiculo."<<endl;
cout<<" 3. Mostrar radares."<<endl; cout<<" 3. Mostrar radares."<<endl;
@@ -19,8 +47,11 @@ int main()
cout<<" 6. Mostrar fichero de sanciones."<<endl; cout<<" 6. Mostrar fichero de sanciones."<<endl;
cout<<" 7. Mostrar cuantia de sancion."<<endl; cout<<" 7. Mostrar cuantia de sancion."<<endl;
cout<<" 8. Salir."<<endl; cout<<" 8. Salir."<<endl;
cout<<"Introduce un opcion";
opcion=getch(); opcion=getch();
}; cout<<opcion;
system("clear"); clear();
};
clear();
return 0; return 0;
}; };