Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. struct alumno
  7. {
  8. int edad;
  9. string nombre;
  10. };
  11.  
  12. int main()
  13. {
  14. struct alumno alumnos[5];
  15. string nombre = "c:\\fichero.txt";
  16. ifstream fichero(nombre);
  17.  
  18. int contador = 0;
  19.  
  20. while (!(fichero.eof()) && contador < 3)
  21. {
  22. fichero >> alumnos[contador].edad;
  23. fichero >> alumnos[contador].nombre;
  24. //getline(fichero, alumnos[contador].nombre);
  25. contador++;
  26. }
  27.  
  28. for (int i = 0; i < contador; i++)
  29. {
  30. cout << alumnos[i].edad << ", " << alumnos[i].nombre;
  31. cout << endl;
  32. }
  33.  
  34. fichero.close();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement