
Error en programa de registro de usuario c++
Publicado por Daniel (1 intervención) el 30/08/2022 22:27:42

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string.h>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
using namespace std;
struct Administrador {
char comercioAdmin[50] = "";
char usuarioAdmin[50] = "";
char passwordAdmin[50]= "";
long cedula=0;
};
string getString(string mjs) {
string m;
cout << mjs << endl;
getline(cin, m);
return m;
}
long getLog(string mjs) {
long m;
cout << mjs << endl;
cin >> m;
return m;
}
Administrador getUsuario(long ced) {
fstream e("Archivos.txt", ios::out | ios::in|ios::binary);
Administrador aux;
if (e.is_open()) {
e.seekg((ced - 1) * sizeof(Administrador));
e.read((char*)&aux, sizeof(Administrador));
e.close();
}
return aux;
}
void registrarAdmin() {
Administrador a;
cin.ignore();
strcpy_s(a.comercioAdmin, getString("Ingresar comercio").c_str());
strcpy_s(a.usuarioAdmin, getString("Ingresar usuario").c_str());
strcpy_s(a.passwordAdmin, getString("Ingresar password").c_str());
a.cedula = getLog("Numero de cedula");
Administrador aux = getUsuario(a.cedula);
if (aux.cedula != 0) {
cout << "Registro Ya existente." << endl;
}
else {
fstream e("Archivos.txt", ios::out | ios::in|ios::binary);
if (e.is_open()) {
e.seekp((a.cedula - 1) * sizeof(Administrador));
e.write((char*)&a, sizeof(Administrador));
e.close();
}
}
}
int menuInicio() {
int opcion;
system("cls");
cout << "1. Agregar." << endl;
cout << "2. Mostrar." << endl;
cout << "3. Buscar." << endl;
cout << "4. Eliminar." << endl;
cout << "5. Modficar." << endl;
cout << "6. Salir." << endl;
cout << "\nIngresar opcion: ";
cin >> opcion;
return opcion;
}
int main() {
ofstream Escribir;
ifstream Lectura;
int opcion = 0;
do {
opcion = menuInicio();
switch (opcion) {
case 1:
registrarAdmin();
break;
case 2:
break;
default:
break;
}
} while (opcion != 6);
return 0;
}
Valora esta pregunta


0