Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. string nombre;
  10. int edad;
  11. double salario;
  12.  
  13. ofstream archivo("empleados.dat");
  14.  
  15. if (!archivo.is_open()) {
  16. cout << "No se pudo abrir el archivo" << endl;
  17. return -1;
  18. } do {
  19. cout << "Ingrese el nombre: ";
  20. getline(cin, nombre);
  21. if (nombre != "") {
  22.  
  23. cout << "Ingrese la edad: ";
  24. cin >> edad;
  25. cin.ignore();
  26. cout << "ingrese el salario: ";
  27. cin >> salario;
  28. cin.ignore();
  29. cout << endl;
  30. //cin.get();
  31. archivo << nombre << "\t" << edad << "\t" << salario << "\t" << endl;
  32.  
  33. }
  34.  
  35. } while (nombre != "");
  36.  
  37.  
  38. archivo.close();
  39.  
  40. getchar();
  41.  
  42. return 0;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement