не считывает данные с файла C++
Неверно считывает файл, в чём причина?
Выводит:
Title:
Players
Platform:
Genre:
Developer:
Year: 4201583
MIN CPU: 0
MIN RUM: 16
MIN HDD: 0
При данных в файле:
- game1
- 2 platform_name
- arakda
- 2002
- 10
- 20
- 30
прога
struct game
{
string title;
string players;
string platform;
string genre;
string developer;
int year;
unsigned int min_cpu; //Мин. частота процессора в МГц
unsigned int min_ram; //Мин. объем опер. памяти в МБ
unsigned int min_hdd; //Мин. объем места на диске в МБ
};
game read_game(ifstream &file)
{
game agame; // создаем новую структуру
getline(file, agame.title); // считываем данные из файла
getline(file, agame.players);
getline(file, agame.platform);
getline(file, agame.genre);
getline(file, agame.developer);
file >> agame.year;
file >> agame.min_cpu;
file >> agame.min_ram;
file >> agame.min_hdd;
file.get();
return agame; // возвращаем результат
}
void print_game(game agame)
{
cout << "\n Название: "; // используем поток cout
cout << agame.title << endl; // для вывода на экран
cout << " Игроки "; // содержимого всех полей
cout << agame.players << endl; // структуры abook
cout << " Платформа: ";
cout << agame.platform<< endl;
cout << " Жанр: ",
cout << agame.genre << endl;
cout << "Разработчик: ",
cout << agame.developer << endl;
cout << "Год: ",
cout << agame.year << endl;
cout << "MIN CPU: ",
cout << agame.min_cpu << endl;
cout << "MIN RUM: ",
cout << agame.min_ram << endl;
cout << "MIN HDD: ",
cout << agame.min_hdd << endl;
}
int N;
game *collection;
int main()
{
setlocale(LC_ALL, "eng");
ifstream infile;
infile.open("my_File.txt");
infile.get();
collection = new game[N];
for (int i = 0; i < N; i++)
collection[i] = read_game(infile);
infile.close();
for (int i = 0; i < N; i++)
print_game(collection[i]);
system("pause");
return 0;
}