Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- struct alumno
- {
- int edad;
- string nombre;
- };
- int main()
- {
- struct alumno alumnos[5];
- string nombre = "c:\\fichero.txt";
- ifstream fichero(nombre);
- int contador = 0;
- while (!(fichero.eof()) && contador < 3)
- {
- fichero >> alumnos[contador].edad;
- fichero >> alumnos[contador].nombre;
- //getline(fichero, alumnos[contador].nombre);
- contador++;
- }
- for (int i = 0; i < contador; i++)
- {
- cout << alumnos[i].edad << ", " << alumnos[i].nombre;
- cout << endl;
- }
- fichero.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement