Intento ingresar una cadena de texto a mi file.txt pero me ingresa la informacion asi
Ü‘|dp|þÿÿÿ no se pq el codigo es el siguiente:
Código:
void ingresar_archivo(string line)
{
ofstream myfile;
//ifstream registro("example.txt", ios::app);
myfile.open ("example.txt",ios::app);
if(myfile.is_open()){
myfile << line<< "HOLA" << endl;
myfile.close();
}else{
cout << "Imposible abrir el archivo" << endl;
}
/* if(registro.bad()){
cout<<"awdawaw";
//Mostrar error
}else{
cout<< "INGRESANDO";
registro >> line;
}
*/
}
void _ingresar()
{
char nombre[30];
char sexo;
int edad;
system("cls");
cout<<"Ingrese el nombre: ";
cin>> nombre;
cout<<"Ingresar Edad:";
cin>>edad;
while(edad < 1 || edad > 90 )
{
cout<<"usted ha ingresado una edad invalidad, Ingresela nuevamente la edad:";
cin>> edad;
}
cout<< "Ingresar sexo (m=masculino o f= femenino):";
cin>> sexo;
char all_char[100];
strcpy(all_char,nombre+' '+sexo+' '+edad);
string all(all_char);
ingresar_archivo(all);
system("pause");
}