Segun yo el problema es con la función mostrar, pues los agrega bien en el archivo.
Muchas gracias de antemano.
Código:
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdlib>
using namespace std;
class User{
public:
void capture();
void show();
void deleteU();
void searchU();
void edit();
char idUser[30];
char name[30];
char mail[40];
char tel[20];
char ranking[30];
char idProfile[30];
};
int main(){
int op;
User x;
int z=1;
cout<<"|||||||||||||||||||||||||||||||||||||||||FILE EDITOR||||||||||||||||||||||||||||||||||||||||"<<endl<<endl;
cout<<"PLEASE TYPE EVERYTHING WITH CAPITAL LETTERS, OTHERWISE YOU MAY HAVE PROBLEMS FINDING A FILE"<<endl;
while(z!=0){
cout<<"What do you want to do?"<<endl;
cout<<"\t 1)Capture"<<endl;
cout<<"\t 2)Show"<<endl;
cout<<"\t 3)Delete"<<endl;
cout<<"\t 4)Search"<<endl;
cout<<"\t 5)Edit"<<endl;
cin>>op;
switch(op)
{
case 1:
x.capture();
break;
case 2:
x.show();
break;
case 3:
x.deleteU();
break;
case 4:
x.searchU();
break;
case 5:
x.edit();
break;
default:
cout<<"Your option was invalid, type a valid number."<<endl;
}
}
return 0;
}
void User::capture()
{
cout<<"Give me the ID USER: ";
cin.ignore();
cin.get(idUser,30);
cout<<"Give me the NAME: ";
cin.ignore();
cin.get(name,30);
cout<<"Give me the MAIL: ";
cin.ignore();
cin.get(mail,40);
cout<<"Give me the TELEPHONE NUMBER: ";
cin.ignore();
cin.get(tel,20);
cout<<"Give me the RANKING: ";
cin.ignore();
cin.get(ranking,30);
cout<<"Give me the ID PROFILE: ";
cin.ignore();
cin.get(idProfile,30);
ofstream write("User.txt",ios::app);
if (!write.good())
{
cout<<"\n\n\tFile not found."<<endl;
}
else
{
write<<idUser<<'|'<<name<<'|'<<mail<<'|'<<tel<<'|'<<ranking<<'|'<<idProfile<<'|'<<'\n';
}
write.close();
}
void User::show()
{
ifstream read;
read.open("User.txt");
char line[200];
read.getline(line,sizeof(line));
while(!read.eof()){
for(int i=0;i<6;i++){
char *pointer;
if(i==0){
pointer = strtok(line,"|");
strcpy(idUser,pointer);
}
else if(i==1){
pointer = strtok(NULL,"|");
strcpy(name,pointer);
}
else if(i==2){
pointer = strtok(NULL,"|");
strcpy(mail,pointer);
}
else if(i==3){
pointer = strtok(NULL,"|");
strcpy(tel,pointer);
}
else if(i==4){
pointer = strtok(NULL,"|");
strcpy(ranking,pointer);
}
else if(i==5){
pointer = strtok(NULL,"|");
strcpy(idProfile,pointer);
}
}
cout<<"ID USER: "<<idUser<<endl;
cout<<"NAME: "<<name<<endl;
cout<<"MAIL: "<<mail<<endl;
cout<<"TEL: "<<tel<<endl;
cout<<"RANKING: "<<ranking<<endl;
cout<<"ID PROFILE: "<<idProfile<<endl;
cout<<"_________________________________"<<endl<<endl;
}
read.close();
}
void User::deleteU()
{
}
void User::searchU()
{
}
void User::edit()
{/*
ofstream aux;
ifstream lectura;
encontrado=false;
int auxClave=0;
char auxNombre[30];
aux.open("auxiliar.txt",ios::out);
lectura.open("alumnos.txt",ios::in);
if(aux.is_open() && lectura.is_open()){
cout<<"Ingresa la Clave del Alumno que deseas Modificar: ";
cin>>auxClave;
lectura>>clave;
while(!lectura.eof()){
lectura>>nombre>>semestre>>grupo>>edad;
if(auxClave==clave){
encontrado=true;
cout<<"__________________________"<<endl;
cout<<"Clave: "<<clave<<endl;
cout<<"Nombre: "<<nombre<<endl;
cout<<"Semestre: "<<semestre<<endl;
cout<<"Grupo: "<<grupo<<endl;
cout<<"Edad: "<<edad<<endl;
cout<<"__________________________"<<endl;
cout<<"Ingresa el Nuevo Nombre del alumno con Clave "<<clave<<": ";
cin>>auxNombre;
aux<<clave<<" "<<auxNombre<<" "<<semestre<<" "<<grupo<<" "<<edad<<endl;
cout<<"Registro Modificado"<<endl;
}else{
aux<<clave<<" "<<nombre<<" "<<semestre<<" "<<grupo<<" "<<edad<<endl;
}
lectura>>clave;
}
}else{
cout<<"No se pudoAbrir el Archivo o aun no ha sido Creado"<<endl;
}
if(encontrado==false){
cout<<"No se encontro ningun registro con clave "<<auxClave<<endl;
}
aux.close();
lectura.close();
remove("alumnos.txt");
rename("auxiliar.txt","alumnos.txt");*/
}