Я читаю файл со следующими данными:
0001 Howard Paredes Zegarra Computacion
0002 Penny Vargas Cordero Industrial
0003 Sheldon Cooper Quizpe Mecatronica
Мой cpp файл выглядит так:
struct Alumno {
char codigo[5];
char nombre[12];
char apellidos[20];
char carrera[15];
};
istream& operator >> (istream &stream, Alumno &record)
{ stream.read(record.codigo, 5);
stream.read(record.nombre, 12);
stream.read(record.apellidos, 20);
stream.read(record.carrera, 15);
stream.get();
return (stream);
}
vector<Alumno> load() {
ifstream file("datos.txt");
vector<Alumno> students;
while (!file.eof()) {
Alumno student = Alumno();
file >> student;
students.push_back(student);
}
file.close();
return (students);
}
int main() {
auto students = load();
for (auto student : students) {
string nombre = student.nombre;
cout << nombre << endl;
}
return (0);
}
, поэтому проблема заключается в том, что при печати печатается переменная "nombre" вся строка меньше первого столбца. Ожидаемый вывод:
Howard
Penny
Sheldon
Но текущий вывод:
Howard Paredes Zegarra Computacion
Penny Vargas Cordero Industrial
Sheldon Cooper Quizpe Mecatronica
почему у меня такой вывод, если у него есть некоторые проблемы с указателем char из моей структуры, любой совет будет быть замечательным Заранее спасибо. Примечание: я не могу использовать строку для этой задачи.