Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- struct Car
- {
- std::string model;
- double fuelConsumption[3];
- double maxSpeed;
- double power;
- };
- int main()
- {
- size_t amount;
- std::cin >> amount;
- std::cout << sizeof(std::string) << std::endl;
- auto array = new Car[amount];
- for (size_t i = 0; i < amount; i++) {
- Car &car = array[i];
- std::cin.ignore();
- std::getline(std::cin, car.model);
- std::cin >> car.fuelConsumption[0];
- std::cin >> car.fuelConsumption[1];
- std::cin >> car.fuelConsumption[2];
- std::cin >> car.maxSpeed;
- std::cin >> car.power;
- }
- std::ofstream outputText("file.txt");
- outputText << amount << std::endl;
- for (size_t i = 0; i < amount; i++) {
- Car &car = array[i];
- outputText << car.model << std::endl;
- outputText << car.fuelConsumption[0] << " ";
- outputText << car.fuelConsumption[1] << " ";
- outputText << car.fuelConsumption[2] << std::endl;
- outputText << car.maxSpeed << std::endl;
- outputText << car.power << std::endl;
- }
- std::ofstream outputBinary("file.bin", std::ios::binary);
- outputBinary << amount << std::endl;
- for (size_t i = 0; i < amount; i++) {
- Car &car = array[i];
- outputBinary.write((char *)&car, sizeof(Car));
- }
- delete[] array;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement